Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

idna.core.InvalidCodepoint and idna.core.IDNAError errors #1405

fxcoudert opened this issue Jun 28, 2018 · 3 comments

idna.core.InvalidCodepoint and idna.core.IDNAError errors #1405

fxcoudert opened this issue Jun 28, 2018 · 3 comments


Copy link

This URL loads with any browser, with cURL and wget, without error:

But trying to reach it with Python requests leads to an error in urllib3:

>>> import requests
>>> requests.get("")
Traceback (most recent call last):
  File "/Users/fx/anaconda3/lib/python3.6/site-packages/idna/", line 271, in alabel
  File "/Users/fx/anaconda3/lib/python3.6/site-packages/idna/", line 311, in ulabel
  File "/Users/fx/anaconda3/lib/python3.6/site-packages/idna/", line 261, in check_label
    raise InvalidCodepoint('Codepoint {0} at position {1} of {2} not allowed'.format(_unot(cp_value), pos+1, repr(label)))
idna.core.InvalidCodepoint: Codepoint U+2603 at position 1 of '☃' not allowed

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/fx/anaconda3/lib/python3.6/site-packages/requests/", line 72, in get
    return request('get', url, params=params, **kwargs)
  File "/Users/fx/anaconda3/lib/python3.6/site-packages/requests/", line 58, in request
    return session.request(method=method, url=url, **kwargs)
  File "/Users/fx/anaconda3/lib/python3.6/site-packages/requests/", line 512, in request
    resp = self.send(prep, **send_kwargs)
  File "/Users/fx/anaconda3/lib/python3.6/site-packages/requests/", line 622, in send
    r = adapter.send(request, **kwargs)
  File "/Users/fx/anaconda3/lib/python3.6/site-packages/requests/", line 445, in send
  File "/Users/fx/anaconda3/lib/python3.6/site-packages/urllib3/", line 600, in urlopen
  File "/Users/fx/anaconda3/lib/python3.6/site-packages/urllib3/", line 343, in _make_request
  File "/Users/fx/anaconda3/lib/python3.6/site-packages/urllib3/", line 849, in _validate_conn
  File "/Users/fx/anaconda3/lib/python3.6/site-packages/urllib3/", line 367, in connect
    cert = self.sock.getpeercert()
  File "/Users/fx/anaconda3/lib/python3.6/site-packages/urllib3/contrib/", line 351, in getpeercert
    'subjectAltName': get_subj_alt_name(x509)
  File "/Users/fx/anaconda3/lib/python3.6/site-packages/urllib3/contrib/", line 228, in get_subj_alt_name
    for name in ext.get_values_for_type(x509.DNSName)
  File "/Users/fx/anaconda3/lib/python3.6/site-packages/urllib3/contrib/", line 228, in <listcomp>
    for name in ext.get_values_for_type(x509.DNSName)
  File "/Users/fx/anaconda3/lib/python3.6/site-packages/urllib3/contrib/", line 181, in _dnsname_to_stdlib
    name = idna_encode(name)
  File "/Users/fx/anaconda3/lib/python3.6/site-packages/urllib3/contrib/", line 179, in idna_encode
    return idna.encode(name)
  File "/Users/fx/anaconda3/lib/python3.6/site-packages/idna/", line 361, in encode
    s = alabel(label)
  File "/Users/fx/anaconda3/lib/python3.6/site-packages/idna/", line 273, in alabel
    raise IDNAError('The label {0} is not a valid A-label'.format(label))
idna.core.IDNAError: The label b'xn--n3h' is not a valid A-label

I originally filed it with pyopenssl: pyca/pyopenssl#771

Copy link

I've got a patch that fixes the issue in #1406. Pending review from others. :)

Copy link

sethmlarson commented Jun 30, 2018

That patch landed in #1406. Closing this issue.

Copy link

Thanks @SethMichaelLarson!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet

No branches or pull requests

2 participants