Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Mailer.send() raises NameError: add_charset, charset_QP, Header and Encoders are not imported (1.20260805.0)

未关闭 适合新手
#1,069 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
1/5
预计耗时
1-3 小时
新手友好度
92/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
python
领域
backend

调研方向

打开 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,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

web2py/py4web 的其他 Issue

查看 web2py/py4web 的全部 Issue

相似的 Issue

更多 Backend & API Design Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。