`http.client.HTTPSConnection._tunnel` raises `AttributeError: 'NoneType' object has no attribute 'encode'` when header value is `None`
維護者通常 1 天內回覆
還沒有人認領這個 Issue。
評估
- 難度
- 2/5
- 預估耗時
- 1-3 小時
- 新手友好度
- 68/100
- Issue 類型
- 缺陷
- 描述清晰度
- 基本清楚
- 活躍度
- 活躍
- 技術堆疊
- python
- 領域
- backend, networking
研究方向
先閱讀 http.client.HTTPSConnection._tunnel 以及 Lib/http/client.py 中對 set_tunnel 的處理;將其行為與報告中指出的 3.10.20 版本進行比較。檢查 Lib/test/test_httplib.py 中現有的通道測試,並新增涵蓋 header 值為 None 的測試。完成標準是該回歸問題已由測試涵蓋,且 _tunnel() 不再因這個輸入而當機。
由索引模型根據 Issue 內容生成。
描述
Bug report
Bug Description
Calling http.client.HTTPSConnection._tunnel() raises AttributeError: 'NoneType' object has no attribute 'encode' when _tunnel_headers contains a header key with a None value.
This regression affects third-party libraries (such as Apache Thrift and CodeChecker) that pass header dictionaries containing None values into set_tunnel(..., headers=...) or HTTP connection objects.
In Python 3.10.21, _tunnel() introduced strict encoding of tunnel headers (value.encode("latin-1")) without checking if the header value is None.
Target Python Version
Python 3.10.21 (Regression introduced between 3.10.20 and 3.10.21)
Operating System
Linux / Ubuntu
Code to Reproduce
import http.client
conn = http.client.HTTPSConnection("127.0.0.1", 8080)
# Set tunnel with a header value of None
conn.set_tunnel("example.com", 443, headers={"X-Test-Header": None})
# Call _tunnel() to trigger the issue
conn._tunnel()
Expected Behavior
_tunnel() should gracefully handle or filter out header keys with None values (or handle string conversions) rather than crashing with an AttributeError.
Actual Behavior
Traceback (most recent call last):
File "reproduce.py", line 9, in
conn._tunnel()
File "/usr/lib/python3.10/http/client.py", line 936, in _tunnel
value_bytes = value.encode("latin-1")
AttributeError: 'NoneType' object has no attribute 'encode'
CPython versions tested on:
3.10
Operating systems tested on:
Linux
- 主要語言
- Python
- 星號
- 77.6k
- 分支
- 37.6k
- 平均合併
- 1 天 20 小時
- 30 天內合併 PR
- 593
環境準備
在瀏覽器裡用你自己的 GitHub 帳號啟動這個專案的開發容器。
- 沒有 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
python/cpython 的其他 Issue
-
docs
難度 1/5 1 小時以內 新手友好度 85/100
維護者通常 1 天內回覆
-
docs
難度 2/5 1-3 小時 新手友好度 62/100
python/cpython#159061 · 1 則留言 ·
維護者通常 1 天內回覆
-
A minor problem with the section "6.10.2. Membership test operations" from the language reference.未關閉docs pending
難度 2/5 1-3 小時 新手友好度 76/100
python/cpython#159034 · 5 則留言 ·
維護者通常 1 天內回覆
-
Docs: socket.htons() and friends raise ValueError for negative input since 3.14可能已有人在做 @vetrovk 於 1 天前認領。 未關閉docs
難度 1/5 1-3 小時 新手友好度 78/100
python/cpython#159012 · 1 則留言 ·
維護者通常 1 天內回覆
-
stdlib topic-profiling type-bug
難度 2/5 1-3 小時 新手友好度 72/100
維護者通常 1 天內回覆
相似的 Issue
-
bug
難度 2/5 1-3 小時 新手友好度 72/100
awslabs/visual-asset-management-system#414 ·
維護者通常 1 天內回覆
-
bug v1 v2
難度 2/5 1-3 小時 新手友好度 75/100
modelcontextprotocol/python-sdk#3670 · 1 則留言 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 82/100
aicell-lab/bioengine#232 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 74/100
modelscope/evalscope#1836 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 72/100