Author rr-
Recipients rr-
Date 2016-08-16.13:55:45
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
Sending requests with Content-Length but without Content-Disposition headers causes following error:

Traceback (most recent call last):
  File "./test", line 19, in <module>
    form = cgi.FieldStorage(fp=env['wsgi.input'], environ=env)
  File "/usr/lib/python3.5/", line 561, in __init__
  File "/usr/lib/python3.5/", line 740, in read_single
  File "/usr/lib/python3.5/", line 762, in read_binary
TypeError: write() argument must be str, not bytes

I've attached a test file that reproduces the issue.

The issue is because read_single decides whether to read the content as binary or text depending on content-length - if it's > 0, it uses read_binary which assumes binary input, and rewrites this input to self.file, assuming self.file is opened in binary mode.

At the same, self.file is opened in text mode, because self._binary_file is set to False, which in turn is because there's no Content-Disposition header.

At very least, the decision whether to use binary or text should be consistent in both places (self.length >= 0 vs self._binary_file).

Note that unlike this issue does NOT concern multipart requests.
Date User Action Args
2016-08-16 13:55:46rr-setrecipients: + rr-
2016-08-16 13:55:45rr-setmessageid: <>
2016-08-16 13:55:45rr-linkissue27777 messages
2016-08-16 13:55:45rr-create