Skip to content

Commit eebf90b

Browse files
committed
Call to_native_string on urls passed to prepare_url
1 parent 466a70f commit eebf90b

2 files changed

Lines changed: 7 additions & 8 deletions

File tree

requests/models.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -325,14 +325,7 @@ def prepare_method(self, method):
325325

326326
def prepare_url(self, url, params):
327327
"""Prepares the given HTTP URL."""
328-
#: Accept objects that have string representations.
329-
try:
330-
url = unicode(url)
331-
except NameError:
332-
# We're on Python 3.
333-
url = str(url)
334-
except UnicodeDecodeError:
335-
pass
328+
url = to_native_string(url)
336329

337330
# Don't do any URL preparation for non-HTTP schemes like `mailto`,
338331
# `data` etc to work around exceptions from `url_parse`, which

test_requests.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,12 @@ def __call__(self, r):
591591
assert resp.json()['headers'][
592592
'Dummy-Auth-Test'] == 'dummy-auth-test-ok'
593593

594+
def test_prepare_request_with_bytestring_url(self):
595+
req = requests.Request('GET', b'https://httpbin.org/')
596+
s = requests.Session()
597+
prep = s.prepare_request(req)
598+
assert prep.url == "https://httpbin.org/"
599+
594600
def test_links(self):
595601
r = requests.Response()
596602
r.headers = {

0 commit comments

Comments
 (0)