Skip to content

Commit 868cd3d

Browse files
committed
Implemented idna (fixes psf#76).
1 parent 39edf7a commit 868cd3d

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

requests/models.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import zlib
1313

1414
from urllib2 import HTTPError
15-
from urlparse import urlparse
15+
from urlparse import urlparse, urlunparse
1616
from datetime import datetime
1717

1818
from .config import settings
@@ -238,6 +238,10 @@ def _encode_params(data):
238238
def _build_url(self):
239239
"""Build the actual URL to use"""
240240

241+
parsed_url = list(urlparse(self.url))
242+
parsed_url[1] = parsed_url[1].encode('idna')
243+
self.url = urlunparse(parsed_url)
244+
241245
if self._enc_params:
242246
if urlparse(self.url).query:
243247
return '%s&%s' % (self.url, self._enc_params)

test_requests.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,9 @@ def test_nonurlencoded_post_query_and_data(self):
321321
self.assertEquals(rbody.get('form'), None)
322322
self.assertEquals(rbody.get('data'), 'foobar')
323323

324+
def test_idna(self):
325+
r = requests.get(u'http://➡.ws/httpbin')
326+
self.assertEqual(r.url, HTTPBIN_URL)
324327

325328

326329
if __name__ == '__main__':

0 commit comments

Comments
 (0)