Inconsistent url parsing between urllib.parse and urllib.request with ":@" in netloc
Aberta
Ninguém assumiu esta issue ainda.
stdlib
type-bug
- Linguagem predominante
- Python
- Estrelas
- 77.2k
- Forks
- 36k
- Métricas de merge de PRs
- Métricas de PR pendentes
Descrição
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
Guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Direção de pesquisa
Comece com urllib.parse.urlsplit e urllib.request.urlopen e, em seguida, rastreie o tratamento de host/port de http.client mostrado no traceback. Compare como cada caminho interpreta https://host:@1/path e identifique o resultado consistente esperado; considera-se concluído quando ambos os caminhos concordarem sem o parsing mismatch relatado e os testes relevantes passarem.
Escrita pelo modelo de indexação a partir do texto da issue.
Avaliação
- Stack de tecnologia
- python
- Domínio
- networking
- Tipo de issue
- Bug
- Dificuldade
- 3/5
- Tempo estimado
- 1-2 dias
- Status de atividade
- Estagnada
- Clareza
- Razoavelmente clara
- Facilidade para iniciantes
- 45/100