This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author srittau
Recipients srittau
Date 2017-11-15.00:31:53
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1510705913.6.0.213398074469.issue32029@psf.upfronthosting.co.za>
In-reply-to
Content
Consider the following code:

    import cgi
    from io import BytesIO

    cgi.FieldStorage(BytesIO(b"{}"), environ={
        "REQUEST_METHOD": "POST",
        "CONTENT_TYPE": "application/json",
        "CONTENT_LENGTH": "14",
    })

This will throw the following exception:

Traceback (most recent call last):
  File "foo.py", line 7, in <module>
    "CONTENT_LENGTH": "14",
  File "/usr/lib/python3.6/cgi.py", line 561, in __init__
    self.read_single()
  File "/usr/lib/python3.6/cgi.py", line 740, in read_single
    self.read_binary()
  File "/usr/lib/python3.6/cgi.py", line 762, in read_binary
    self.file.write(data)
TypeError: write() argument must be str, not bytes

Of course, the input does not contain any argument string to be parsed by FieldStorage. Nevertheless, a TypeError in a totally unrelated part of the code seems like a bug. In my opinion, FieldStorage should just remain empty in this case, or - at best - throw a ValueError with a sensible error message.
History
Date User Action Args
2017-11-15 00:31:53srittausetrecipients: + srittau
2017-11-15 00:31:53srittausetmessageid: <1510705913.6.0.213398074469.issue32029@psf.upfronthosting.co.za>
2017-11-15 00:31:53srittaulinkissue32029 messages
2017-11-15 00:31:53srittaucreate