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

Passthrough for things that appear as hostnames (like IP addresses) #58

Closed
wumpus opened this issue Dec 30, 2017 · 2 comments
Closed

Passthrough for things that appear as hostnames (like IP addresses) #58

wumpus opened this issue Dec 30, 2017 · 2 comments

Comments

@wumpus
Copy link

wumpus commented Dec 30, 2017

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
@wumpus
Copy link
Author

wumpus commented May 21, 2018

Python 3.7 will fix the built-in codec to work.

@wumpus wumpus closed this as completed May 21, 2018
@kjd kjd reopened this Jun 11, 2018
JanZerebecki added a commit to JanZerebecki/eventlet that referenced this issue Sep 27, 2018
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
@JanZerebecki
Copy link

I stumbled upon this because of urllib3/urllib3#1269

@kjd kjd changed the title difference with Python idna codec Passthrough for things that appear as hostnames (like IP addresses) Feb 25, 2020
@kjd kjd closed this as completed Oct 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants