You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Thanks for this code, it's nice to see support for modern urls in Python! The built-in codec raises for any hostname containing ß, complaining
UnicodeError: ('IDNA does not round-trip', b'xn--einla-pqa', b'einlass')
idna 2008 fixes this stupidity.
However, when you're dealing with general-purpose urls you end up with hostnames like '::1', which is localhost for ipv6. This means that your module isn't so easy to drop in as a replacement. I either need to wrap it or stick try / except idna.core.InvalidCodepoint in my code, which looks a bit odd. I think it might be prettier if idna encode/decode grew options to pass-thru in this case?
>>> u='::1'
>>> u.encode('idna')
b'::1'
>>> import idna
>>> idna.encode(u)
Traceback (most recent call last):
File "/home/lindahl/.pyenv/versions/3.6.4/lib/python3.6/site-packages/idna/core.py", line 263, in alabel
ulabel(label)
File "/home/lindahl/.pyenv/versions/3.6.4/lib/python3.6/site-packages/idna/core.py", line 299, in ulabel
check_label(label)
File "/home/lindahl/.pyenv/versions/3.6.4/lib/python3.6/site-packages/idna/core.py", line 253, 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+003A at position 1 of '::1' not allowed
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/lindahl/.pyenv/versions/3.6.4/lib/python3.6/site-packages/idna/core.py", line 355, in encode
result.append(alabel(label))
File "/home/lindahl/.pyenv/versions/3.6.4/lib/python3.6/site-packages/idna/core.py", line 265, in alabel
raise IDNAError('The label {0} is not a valid A-label'.format(label))
idna.core.IDNAError: The label b'::1' is not a valid A-label
The text was updated successfully, but these errors were encountered:
This will fail when the package idna is in use on Python 2. My guess
from a quick skim of the spec is that trying to apply IDNA to IP
adresses is wrong.
See also kjd/idna#58
Thanks for this code, it's nice to see support for modern urls in Python! The built-in codec raises for any hostname containing ß, complaining
UnicodeError: ('IDNA does not round-trip', b'xn--einla-pqa', b'einlass')
idna 2008 fixes this stupidity.
However, when you're dealing with general-purpose urls you end up with hostnames like '::1', which is localhost for ipv6. This means that your module isn't so easy to drop in as a replacement. I either need to wrap it or stick try / except idna.core.InvalidCodepoint in my code, which looks a bit odd. I think it might be prettier if idna encode/decode grew options to pass-thru in this case?
The text was updated successfully, but these errors were encountered: