Invalid `params` type (e.g. int) raises misleading "TypeError: Cannot mix str and non-str arguments"
まだ誰も着手していません。
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 72/100
調査の方向性
リクエストの準備中に params がどのように処理されるかを追い、issue が示す経路に沿って URL の準備から urllib.parse.urlunparse まで確認してください。リクエスト準備コードと、クエリパラメーターまたは無効な入力に関する既存のテストから始めてください。整数などの無効な型のテストを追加し、発生するエラーが params に言及し、受け付ける型を説明していることを確認してください。
索引モデルが issue の本文から書いたものです。
説明
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"
}
}
- 主要言語
- Python
- スター
- 54.7k
- フォーク
- 10.8k
- 平均マージ
- 18分
- マージ済み PR(30日)
- 1
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
psf/requests のほかの issue
-
難易度 1/5 1時間未満 初心者へのやさしさ 85/100
-
`iter_lines(decode_unicode=True, delimiter=<str>)` raises `TypeError` when `Response.encoding` is `None`再び着手できるかも このイシューのプルリクエストはマージされずにクローズされました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
-
get_encoding_from_headers treats any content type containing 'text' as text/* (ISO-8859-1)対応中かも @suyashgitt が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
OCA/account-invoicing#2529 ·
メンテナーはふだん 1 日以内に返信
-
area/ci
難易度 1/5 1時間未満 初心者へのやさしさ 62/100
メンテナーはふだん 1 日以内に返信
-
ImageGen generate-batch aborts valid JSONL jobs containing a Unicode line separator in poster textオープンbug imagen skills
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
Email validation accepts a trailing newline対応中かも @marcello-pichini が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
メンテナーはふだん 1 日以内に返信