-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
Closed
Labels
stdlibPython modules in the Lib dirPython modules in the Lib dirtopic-emailtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Bug report
Bug description:
html_body = part.get_payload(decode=True).decode()
File "/usr/local/lib/python3.8/email/message.py", line 282, in get_payload
return quopri.decodestring(bpayload)
CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux
Linked PRs
- gh-134759:
UnboundLocalError
inemail.message.Message.get_payload
#136071 - [3.14] gh-134759: fix
UnboundLocalError
inemail.message.Message.get_payload
(GH-136071) #136579 - [3.13] gh-134759: fix
UnboundLocalError
inemail.message.Message.get_payload
(GH-136071) #136580 - Fix UnboundLocalError in email.message.Message.get_payload (GH-134759) Cline Fix #136751
Metadata
Metadata
Assignees
Labels
stdlibPython modules in the Lib dirPython modules in the Lib dirtopic-emailtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Projects
Milestone
Relationships
Development
Select code repository
Activity
[-]UnboundLocalError: local variable 'bpayload' referenced before assignment[/-][+]`UnboundLocalError` in `email.message.Message.get_payload`[/+]picnixz commentedon May 26, 2025
The error is here:
cpython/Lib/email/message.py
Lines 316 to 317 in 96905bd
cc @bitdancer
makridenko commentedon May 27, 2025
hi, can i work on this?
skv0zsneg commentedon May 27, 2025
Hello! I would like to work on it but did not work with CPython at all. Will it be a problem? If not where I should start with?
sobolevn commentedon May 27, 2025
Hi, @skv0zsneg and @makridenko! Thanks a lot for your interest.
@makridenko since you were first, you can surely work on this. Because it looks like that no one else has started yet.
@skv0zsneg we value new contributors, please, don't feel left out :) You can pick any other issue from the opened ones 🤝
skv0zsneg commentedon Jun 27, 2025
Hey everyone!
Trying to reproduce this bug
UnboundLocalError
but it want falling.What I'm doing in REPL:
As mentioned by @picnixz, the error must be on line 317. To get here I use email message with
quoted-printable
encoding and body message surely get intoquopri.decodestring
but (luckly?) it does not fall. Am I miss something?OS: Linux (Ubuntu 24.04.2 LTS)
Python: Python 3.15.0a0
picnixz commentedon Jun 27, 2025
The "bad" code path is only taken when
payload
is not a string,cte == 'quoted-printable'
anddecode
is True. Considering there isWe can't just use a list because if
is_multipart()
would return true and we would early exit. So we need to use a bytes payload withdecode = True
(I think).UnboundLocalError
inemail.message.Message.get_payload
#136071email.message.Message.set_payload
#136397gh-134759: fix `UnboundLocalError` in `email.message.Message.get_payl…
pythongh-134759: fix `UnboundLocalError` in `email.message.Message.ge…
pythongh-134759: fix `UnboundLocalError` in `email.message.Message.ge…
UnboundLocalError
inemail.message.Message.get_payload
(GH-136071) #136579UnboundLocalError
inemail.message.Message.get_payload
(GH-136071) #136580[3.13] gh-134759: fix `UnboundLocalError` in `email.message.Message.g…
[3.14] gh-134759: fix `UnboundLocalError` in `email.message.Message.g…
pythongh-134759: fix `UnboundLocalError` in `email.message.Message.ge…
pythongh-134759: fix `UnboundLocalError` in `email.message.Message.ge…
pythongh-134759: fix `UnboundLocalError` in `email.message.Message.ge…