Inconsistent url parsing between urllib.parse and urllib.request with ":@" in netloc
Abierto
Nadie ha tomado este issue todavía.
stdlib
type-bug
- Lenguaje dominante
- Python
- Estrellas
- 77.2k
- Forks
- 36k
- Métricas de merge de PR
- Métricas de PR pendientes
Descripción
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
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Empieza con urllib.parse.urlsplit y urllib.request.urlopen; después, sigue el manejo de host/port de http.client mostrado en el traceback. Compara cómo interpreta cada ruta https://host:@1/path e identifica el resultado coherente esperado; se considera terminado cuando ambas rutas coinciden sin el parsing mismatch informado y las pruebas relevantes pasan.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- python
- Área
- networking
- Tipo de issue
- Error
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 45/100