email.policy.SMTP TypeError: 'Header' object is not subscriptable
还没有人认领这个 Issue。
评估
调研方向
首先使用 email.message.Message、email.policy.SMTP 和 email.header.Header 运行提供的复现程序。通过 email/message.py、email/policy.py、email/headerregistry.py 和 email/_header_value_parser.py 跟踪故障,然后将其与默认 policy 的行为进行比较。当 SMTP policy 示例不再引发报告中的 TypeError,并保留文档所述的输出行为时,即表示完成。
由索引模型根据 Issue 内容生成。
描述
Bug report
Code snippet is taken directly from documentation https://docs.python.org/3/library/email.header.html
The only change - policy changed to email.policy.SMTP.
Documentation (https://docs.python.org/3/library/email.policy.html#email.policy.SMTP) states that the only difference between email.policy.default and email.policy.SMTP - linesep used.
from email.message import Message
from email.header import Header
from email.policy import SMTP
msg = Message()
h = Header('p\xf6stal', 'iso-8859-1')
msg['Subject'] = h
print(msg.as_string())
msg = Message(policy=SMTP)
h = Header('p\xf6stal', 'iso-8859-1')
msg['Subject'] = h
print(msg.as_string())
Output is:
Subject: =?iso-8859-1?q?p=F6stal?=
Traceback (most recent call last):
File "C:\Users\barsk\AppData\Roaming\JetBrains\PyCharm2022.3\scratches\scratch_3.py", line 12, in <module>
msg['Subject'] = h
File "C:\Program Files (x86)\Python37-32\lib\email\message.py", line 409, in __setitem__
self._headers.append(self.policy.header_store_parse(name, val))
File "C:\Program Files (x86)\Python37-32\lib\email\policy.py", line 148, in header_store_parse
return (name, self.header_factory(name, value))
File "C:\Program Files (x86)\Python37-32\lib\email\headerregistry.py", line 589, in __call__
return self[name](name, value)
File "C:\Program Files (x86)\Python37-32\lib\email\headerregistry.py", line 197, in __new__
cls.parse(value, kwds)
File "C:\Program Files (x86)\Python37-32\lib\email\headerregistry.py", line 272, in parse
kwds['parse_tree'] = cls.value_parser(value)
File "C:\Program Files (x86)\Python37-32\lib\email\_header_value_parser.py", line 1105, in get_unstructured
if value[0] in WSP:
TypeError: 'Header' object is not subscriptable
Your environment
Reproduced on windows on
- Python 3.11 (64-bit)
- Python 3.10 (64-bit)
- Python 3.7 (32-bit)
- 主要语言
- Python
- 星标
- 77.2k
- 派生
- 36k
- 平均合并
- 1 天 9 小时
- 30 天内合并 PR
- 558
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
python/cpython 的其他 Issue
-
docs pending
难度 2/5 1-3 小时 新手友好度 78/100
-
stdlib type-feature
难度 2/5 1-3 小时 新手友好度 78/100
-
stdlib type-feature
难度 2/5 1-3 小时 新手友好度 72/100
-
build type-bug
难度 2/5 1-3 小时 新手友好度 76/100
-
stdlib topic-email type-feature
难度 2/5 1-3 小时 新手友好度 70/100
相似的 Issue
-
area/auth bug comp/agent P3 platform/discord type/security
难度 2/5 1-3 小时 新手友好度 88/100
NousResearch/hermes-agent#117848 ·
-
难度 2/5 1-3 小时 新手友好度 74/100
bancolombia/sentinel#23 ·
-
test md 未关闭CI
难度 2/5 1-3 小时 新手友好度 74/100
-
integration:quickjs org:external priority:backlog topic:code-interpreter topic:middleware type:feature
难度 2/5 1-3 小时 新手友好度 74/100
langchain-ai/deepagents#6450 ·
-
bug client
难度 2/5 1-3 小时 新手友好度 88/100