email.policy.SMTP TypeError: 'Header' object is not subscriptable
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Python
- Star
- 77.2k
- Fork
- 36k
- Merge trung bình
- 1 ngày 9 giờ
- Pull request đã merge (30 ngày)
- 558
Mô tả
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)
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu bằng cách chạy reproducer được cung cấp với email.message.Message, email.policy.SMTP và email.header.Header. Theo dõi lỗi qua email/message.py, email/policy.py, email/headerregistry.py và email/_header_value_parser.py, sau đó so sánh với hành vi của policy mặc định. Công việc được hoàn tất khi ví dụ sử dụng policy SMTP không còn gây ra TypeError đã báo cáo và vẫn giữ nguyên hành vi đầu ra được ghi trong tài liệu.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- python
- Lĩnh vực
- backend
- Loại issue
- Lỗi
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức phù hợp với người mới
- 35/100