Invalid `params` type (e.g. int) raises misleading "TypeError: Cannot mix str and non-str arguments"
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 72/100
Hướng nghiên cứu
Theo dõi cách params được xử lý trong quá trình chuẩn bị yêu cầu, lần theo đường đi của issue qua bước chuẩn bị URL đến urllib.parse.urlunparse. Bắt đầu với mã chuẩn bị yêu cầu và các bài kiểm thử hiện có cho tham số truy vấn hoặc đầu vào không hợp lệ. Bổ sung kiểm thử cho các kiểu không hợp lệ như số nguyên, đồng thời xác nhận lỗi phát sinh có nhắc đến params và mô tả các kiểu được chấp nhận.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
The error raised when params has an invalid type (for example an int) is misleading: TypeError: Cannot mix str and non-str arguments comes from urllib.parse and doesn't mention params, so it is hard to tell what the caller did wrong.
Expected Result
An error that names the invalid argument, for example:
TypeError: params must be a dict, a list of tuples, or a str/bytes, not int
I'm not asking for new functionality, only that the existing error identify the invalid argument.
Actual Result
TypeError: Cannot mix str and non-str arguments
The error is raised from urllib.parse._coerce_args, called from urlunparse while the URL is being prepared, so nothing in the message points back to params. A similar report, #2844 (params=b"..."), was treated as a bug and fixed in 2015. This report is about other invalid types.
I ran this in a browser-based Python (Emscripten/Pyodide), but the error is raised from urllib.parse, which is pure Python, so I'd expect it on any platform.
Reproduction Steps
import requests
print(requests.__version__)
requests.Request("GET", "http://example.com/path", params=5).prepare().url
Reproduced on requests 2.31.0 with params=5. The same TypeError also occurs with params=3.14, params=True and params=object() (these three were tested on requests 2.33.1 on Linux, Python 3.12).
System Information
$ python -m requests.help
{
"platform": {
"system": "Emscripten",
"release": "3.1.58"
},
"implementation": {
"name": "CPython",
"version": "3.12.7"
},
"system_ssl": {
"version": "1010117f"
},
"using_pyopenssl": false,
"using_charset_normalizer": true,
"pyOpenSSL": {
"version": null,
"openssl_version": ""
},
"urllib3": {
"version": "2.2.3"
},
"chardet": {
"version": null
},
"charset_normalizer": {
"version": "3.3.2"
},
"cryptography": {
"version": ""
},
"idna": {
"version": "3.7"
},
"requests": {
"version": "2.31.0"
}
}
- Ngôn ngữ chính
- Python
- Star
- 54.7k
- Fork
- 10.8k
- Merge trung bình
- 18 phút
- Pull request đã merge (30 ngày)
- 1
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc 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.
Issue khác của psf/requests
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 85/100
-
`iter_lines(decode_unicode=True, delimiter=<str>)` raises `TypeError` when `Response.encoding` is `None`Có thể làm lại được Pull request cho issue này đã bị đóng mà không được merge. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
-
get_encoding_from_headers treats any content type containing 'text' as text/* (ISO-8859-1)Có thể đã có người làm @suyashgitt đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
OCA/account-invoicing#2529 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
area/ci
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 62/100
Maintainer thường phản hồi trong vòng 1 ngày
-
ImageGen generate-batch aborts valid JSONL jobs containing a Unicode line separator in poster textĐang mởbug imagen skills
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Email validation accepts a trailing newlineCó thể đã có người làm @marcello-pichini đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
Maintainer thường phản hồi trong vòng 1 ngày