`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 天 10 小时
- 30 天内合并 PR
- 573
环境准备
在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
python/cpython 的其他 Issue
-
A minor problem with the section "6.10.2. Membership test operations" from the language reference.未关闭docs
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 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 天内回复
-
stdlib type-bug
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
lazy import of `_sysconfig` in `Lib/ctypes/__init__.py` is eager on android and cygwin可能已有人在做 @sillyfellow21 于 4 天前认领。 未关闭tests topic-lazy-imports
难度 2/5 1-3 小时 新手友好度 74/100
python/cpython#158684 · 4 条评论 ·
维护者通常 1 天内回复
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 68/100
pyjanitor-devs/pyjanitor#1758 ·
维护者通常 1 天内回复
-
bug ready for review
难度 2/5 1-3 小时 新手友好度 86/100
odysseus-dev/odysseus#6641 ·
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 76/100
happypawspillaro/happypaws#78 ·
维护者通常 4 天内回复
-
pydanty:is-working
难度 2/5 1-3 小时 新手友好度 82/100
pydantic/pydantic-ai#10020 ·
维护者通常 1 天内回复
-
Bug
难度 2/5 1-3 小时 新手友好度 78/100
ansible-collections/ibm_zos_core#2650 ·