email.policy.SMTP TypeError: 'Header' object is not subscriptable
まだ誰も着手していません。
評価
調査の方向性
まず、提供された再現コードを email.message.Message、email.policy.SMTP、email.header.Header とともに実行します。email/message.py、email/policy.py、email/headerregistry.py、email/_header_value_parser.py をたどって失敗の原因を追跡し、その後、デフォルトポリシーの動作と比較します。SMTP ポリシーの例で報告された 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時間
- マージ済み PR(30日)
- 558
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- 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
-
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
PolicyEngine/policyengine-us#9559 ·
-
priority: p3
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
googleapis/librarian#7636 ·
-
from:qa priority:P2 reliability tech-debt
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
spec-kitty/spec-kitty#4874 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100