'NoneType' object has no attribute 'encode' in requestReceived() when multipart body doesn't include content-disposition
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
twisted (Debian) |
Fix Released
|
Unknown
|
|||
twisted (Ubuntu) |
Fix Released
|
Medium
|
Victor Tapia | ||
Focal |
Fix Released
|
Medium
|
Victor Tapia | ||
Groovy |
Fix Released
|
Medium
|
Victor Tapia | ||
Hirsute |
Fix Released
|
Medium
|
Victor Tapia |
Bug Description
[impact]
python-twisted errors out with "'NoneType' object has no attribute 'encode' in requestReceived()" when it tries to parse a multipart mime message and python3.7+ is used. This happens because before commit cc3fa20 in cpython, cgi.parse_multipart ignored parts without a name defined in "content-
[scope]
Even though this bug affects all python3-twisted releases, I'll backport the fix just to Focal, Groovy and Hirsute. Bionic and Xenial do not have Python 3.7 as the default interpreter (required to trigger the issue), and the delta in python3-twisted might be to big to backport as the current packages do not contemplate _PY37PLUS at all.
Fixed upstream with commit 310496249, available since 21.2.0rc1
[test case]
1. Save the following code as webserver.py
from twisted.
from twisted.
from twisted.
from twisted.web.server import Site
class Foo(Resource):
def render_POST(self, request):
newdata = request.
return ''
root = Resource()
root.putChild(
application = Application(
TCPServer(8080, Site(root)
2. Save the following code as client.py (python3-httplib2 is required)
#!/usr/bin/env python
import httplib2
def http_request(url, method, body=None, headers=None, insecure=False):
"""Issue an http request."""
http = httplib2.
if isinstance(url, bytes):
url = url.decode("ascii")
return http.request(url, method, body=body, headers=headers)
url = "http://
method = "POST"
headers = {'Content-Type': 'multipart/
emptyh = '--882589981242
print("== BODY: " + emptyh + "\n")
response, content = http_request(url, method, emptyh, headers)
3. Run the server with "twistd3 -y webserver.py"
4. Run the client
5. twistd will fail to encode the key and will drop this traceback in the log file (twistd.log)
2021-02-
Traceback (most recent call last):
File "/usr/lib/
return callWithContext
File "/usr/lib/
return context.
File "/usr/lib/
return self.currentCon
File "/usr/lib/
return func(*args,**kw)
--- <exception caught here> ---
File "/usr/lib/
why = selectable.doRead()
File "/usr/lib/
return self._dataRecei
File "/usr/lib/
rval = self.protocol.
File "/usr/lib/
return self._channel.
File "/usr/lib/
return basic.LineRecei
File "/usr/lib/
why = self.rawDataRec
File "/usr/lib/
File "/usr/lib/
File "/usr/lib/
File "/usr/lib/
File "/usr/lib/
File "/usr/lib/
[regression potential]
This affects the returned dictionaries with non-str keys, which were discarded in python3.6 or earlier before they reached twisted, so patching this will make its behavior consistent.
description: | updated |
tags: | added: sts-sponsor-ddstreet |
Changed in twisted (Ubuntu Hirsute): | |
assignee: | nobody → Victor Tapia (vtapia) |
Changed in twisted (Ubuntu Groovy): | |
assignee: | nobody → Victor Tapia (vtapia) |
Changed in twisted (Ubuntu Focal): | |
assignee: | nobody → Victor Tapia (vtapia) |
Changed in twisted (Ubuntu Hirsute): | |
importance: | Undecided → Medium |
Changed in twisted (Ubuntu Groovy): | |
importance: | Undecided → Medium |
Changed in twisted (Ubuntu Focal): | |
importance: | Undecided → Medium |
Changed in twisted (Ubuntu Hirsute): | |
status: | New → In Progress |
Changed in twisted (Ubuntu Groovy): | |
status: | New → In Progress |
Changed in twisted (Ubuntu Focal): | |
status: | New → In Progress |
Changed in twisted (Debian): | |
status: | Unknown → New |
tags: | removed: sts-sponsor-ddstreet |
Changed in twisted (Debian): | |
status: | New → Fix Released |
The attachment "hirsute.debdiff" seems to be a debdiff. The ubuntu-sponsors team has been subscribed to the bug report so that they can review and hopefully sponsor the debdiff. If the attachment isn't a patch, please remove the "patch" flag from the attachment, remove the "patch" tag, and if you are member of the ~ubuntu-sponsors, unsubscribe the team.
[This is an automated message performed by a Launchpad user owned by ~brian-murray, for any issue please contact him.]