Mailer.send() raises NameError: add_charset, charset_QP, Header and Encoders are not imported (1.20260805.0)
还没有人认领这个 Issue。
评估
调研方向
打开 py4web/utils/mailer.py,检查 pyflakes 报告的未定义名称:add_charset、charset_QP、Header 和 Encoders。使用 Mailer.send() 示例复现该失败,然后验证普通消息和附件处理不再引发 NameError,并且 UTF-8 quoted-printable 消息能被正确构建。
由索引模型根据 Issue 内容生成。
描述
Description
In py4web 1.20260805.0 (the latest release on PyPI), and on current master, Mailer.send() raises NameError on every call, so no email can be sent. That includes the emails sent by Auth.
py4web/utils/mailer.py uses four names that it never imports:
| Line | Name |
|---|---|
| 391 | add_charset |
| 391 | charset_QP |
| 395 | Header |
| 235 | Encoders (attachments only) |
They used to come from from pydal._compat import *. Commit 1df05c3 ("last py4web version before the pydal refactor") removed that import without replacing those four names. pyflakes py4web/utils/mailer.py reports them as undefined.
Steps to reproduce
from py4web.utils.mailer import Mailer
m = Mailer(server="logging", sender="[email protected]")
m.send("[email protected]", "subject", "body")
Actual result
File ".../py4web/utils/mailer.py", line 391, in send
add_charset("utf-8", charset_QP, charset_QP, "utf-8")
^^^^^^^^^^^
NameError: name 'add_charset' is not defined
Suggested fix
Add the missing imports to py4web/utils/mailer.py:
from email import encoders as Encoders
from email.charset import QP as charset_QP
from email.charset import add_charset
from email.header import Header
I am working around it at the application level by injecting these names into py4web.utils.mailer. With that in place, send() builds a correct quoted-printable UTF-8 message and hands it to SMTP.
Environment
- py4web 1.20260805.0
- pydal 20260520.0
- Python 3.12 (Linux and Google App Engine)
- 主要语言
- HTML
- 星标
- 319
- 派生
- 144
- 平均合并
- 1 分钟
- 30 天内合并 PR
- 1
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
web2py/py4web 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 75/100
-
难度 3/5 1-2 天 新手友好度 48/100
-
难度 5/5 一周以上 新手友好度 30/100
-
难度 4/5 3-5 天 新手友好度 38/100
-
难度 2/5 1-3 小时 新手友好度 50/100
相似的 Issue
-
manager: startAgent retains the caller's subscribe/allowSubscribe/allowPublish arrays by reference未关闭area:manager bug triage:confirmed
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 1 天内回复
-
area: capture good first issue priority: P2 type: defect
难度 2/5 1-3 小时 新手友好度 78/100
jiegui2025/hwspec#51 ·
维护者通常 1 天内回复
-
[Feature]:未关闭enhancement
难度 2/5 1-3 小时 新手友好度 65/100
-
难度 2/5 1-3 小时 新手友好度 72/100
thephpleague/commonmark#1159 ·