Inconsistent url parsing between urllib.parse and urllib.request with ":@" in netloc
Đang mở
Chưa có ai nhận issue này.
stdlib
type-bug
- Ngôn ngữ chính
- Python
- Star
- 77.2k
- Fork
- 36k
- Chỉ số merge pull request
- Chỉ số pull request đang chờ
Mô tả
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
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu với urllib.parse.urlsplit và urllib.request.urlopen, sau đó lần theo cách http.client xử lý host/port được thể hiện trong traceback. So sánh cách mỗi đường đi diễn giải https://host:@1/path và xác định kết quả nhất quán được mong đợi; hoàn tất khi cả hai đường đi cho cùng kết quả mà không còn parsing mismatch đã được báo cáo và các bài kiểm thử liên quan đều đạt.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- python
- Lĩnh vực
- networking
- Loại issue
- Lỗi
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 45/100