Inconsistent url parsing between urllib.parse and urllib.request with ":@" in netloc
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 77.2k
- Forks
- 36k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
Bug report
With "https://host:@1/path", urlib.parse.urlsplit parses "host" as the user and "1" as the hostname with no port.
If I use this url with urllib.request.urlopen, it parses "@1" as being the port.
Python 3.9.6 (default, Jun 28 2021, 08:57:49)
[GCC 11.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from urllib.parse import urlsplit
>>> s = urlsplit("https://host:@1/path")
>>> s.hostname
'1'
>>> s.port
>>> s.username
'host'
>>> import urllib.request
>>> urllib.request.urlopen(urllib.request.Request("https://host:@1/path"))
Traceback (most recent call last):
File "/usr/lib/python3.9/http/client.py", line 872, in _get_hostport
ValueError: invalid literal for int() with base 10: '@1'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.9/urllib/request.py", line 214, in urlopen
File "/usr/lib/python3.9/urllib/request.py", line 517, in open
File "/usr/lib/python3.9/urllib/request.py", line 534, in _open
File "/usr/lib/python3.9/urllib/request.py", line 494, in _call_chain
File "/usr/lib/python3.9/urllib/request.py", line 1389, in https_open
File "/usr/lib/python3.9/urllib/request.py", line 1315, in do_open
File "/usr/lib/python3.9/http/client.py", line 1384, in __init__
File "/usr/lib/python3.9/http/client.py", line 834, in __init__
File "/usr/lib/python3.9/http/client.py", line 877, in _get_hostport
http.client.InvalidURL: nonnumeric port: '@1'
Your environment
- CPython versions tested on: 3.9.6
- Operating system and architecture: Linux
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne mit urllib.parse.urlsplit und urllib.request.urlopen und verfolge anschließend die in der traceback gezeigte host/port-Verarbeitung von http.client. Vergleiche, wie jeder Pfad https://host:@1/path interpretiert, und ermittle das erwartete konsistente Ergebnis; als abgeschlossen gilt die Aufgabe, wenn beide Pfade ohne das gemeldete Parsing-Mismatch dasselbe Ergebnis liefern und die relevanten Tests erfolgreich durchlaufen.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- networking
- Issue-Typ
- Bug
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 45/100