mirror of
https://github.com/kennethreitz/requests.git
synced 2026-06-05 22:50:18 +00:00
Use IDNA2008 to encode hosts.
This commit is contained in:
+3
-2
@@ -21,6 +21,7 @@ from .structures import CaseInsensitiveDict
|
||||
|
||||
from .auth import HTTPBasicAuth
|
||||
from .cookies import cookiejar_from_dict, get_cookie_header, _copy_cookie_jar
|
||||
from .packages import idna
|
||||
from .packages.urllib3.fields import RequestField
|
||||
from .packages.urllib3.filepost import encode_multipart_formdata
|
||||
from .packages.urllib3.util import parse_url
|
||||
@@ -363,8 +364,8 @@ class PreparedRequest(RequestEncodingMixin, RequestHooksMixin):
|
||||
|
||||
# Only want to apply IDNA to the hostname
|
||||
try:
|
||||
host = host.encode('idna').decode('utf-8')
|
||||
except UnicodeError:
|
||||
host = idna.encode(host).decode('utf-8')
|
||||
except (UnicodeError, idna.IDNAError):
|
||||
raise InvalidURL('URL has an invalid label.')
|
||||
|
||||
# Carefully reconstruct the network location
|
||||
|
||||
Reference in New Issue
Block a user