Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Unexpected exceptions whenemail.policy.Policy.max_line_length is falsey #135307

Closed
Labels
3.13bugs and security fixes3.14bugs and security fixes3.15new features, bugs and security fixesstdlibStandard Library Python modules in the Lib/ directorytopic-emailtype-bugAn unexpected behavior, bug, or error
@ptwales

Description

@ptwales

Bug report

Bug description:

From thedocumentation

max_line_length

The maximum length of any line in the serialized output, not counting the end of line character(s). Default is 78, perRFC 5322. A value of 0 orNone indicates that no line wrapping should be done at all.

If I follow this documentation thenset_content will fail. If I use the providedemail.policy.HTTP, which disables word wrapping, it also fails.

fromemailimportpolicyfromemail.messageimportEmailMessagemsg=EmailMessage(policy=policy.default.clone(max_line_length=None))msg["From"]="noreply@example.com"msg["To"]="noreply@example.com"msg["Subject"]="Email no wrap fails"msg.set_content("This line fails")print(msg)

Stack trace:

  File "/usr/lib/python3.13/email/message.py", line 1207, in set_content    super().set_content(*args, **kw)    ~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^  File "/usr/lib/python3.13/email/message.py", line 1137, in set_content    content_manager.set_content(self, *args, **kw)    ~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^  File "/usr/lib/python3.13/email/contentmanager.py", line 37, in set_content    handler(msg, obj, *args, **kw)    ~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^  File "/usr/lib/python3.13/email/contentmanager.py", line 187, in set_text_content    cte, payload = _encode_text(string, charset, cte, msg.policy)                   ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  File "/usr/lib/python3.13/email/contentmanager.py", line 151, in _encode_text    if max((len(x) for x in lines), default=0) <= policy.max_line_length:       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^TypeError: '<=' not supported between instances of 'int' and 'NoneType'

Usingmax_line_length=0 gives a different error:

  File "/usr/lib/python3.13/email/message.py", line 1207, in set_content    super().set_content(*args, **kw)    ~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^  File "/usr/lib/python3.13/email/message.py", line 1137, in set_content    content_manager.set_content(self, *args, **kw)    ~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^  File "/usr/lib/python3.13/email/contentmanager.py", line 37, in set_content    handler(msg, obj, *args, **kw)    ~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^  File "/usr/lib/python3.13/email/contentmanager.py", line 187, in set_text_content    cte, payload = _encode_text(string, charset, cte, msg.policy)                   ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  File "/usr/lib/python3.13/email/contentmanager.py", line 159, in _encode_text    sniff_qp = quoprimime.body_encode(sniff.decode('latin-1'),                                      policy.max_line_length)  File "/usr/lib/python3.13/email/quoprimime.py", line 173, in body_encode    raise ValueError("maxlinelen must be at least 4")

CPython versions tested on:

3.13

Operating systems tested on:

Linux

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.13bugs and security fixes3.14bugs and security fixes3.15new features, bugs and security fixesstdlibStandard Library Python modules in the Lib/ directorytopic-emailtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp