classification
Title: cgi.FieldStorage is broken when given POST data
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.1, Python 3.2, Python 2.7
process
Status: closed Resolution: duplicate
Dependencies: Superseder: WSGI, cgi.FieldStorage incompatibility
View: 1573931
Assigned To: Nosy List: MHordecki, efosmark, eric.araujo, flox, milesck
Priority: normal Keywords:

Created on 2009-06-07 22:07 by efosmark, last changed 2011-07-02 13:41 by eric.araujo. This issue is now closed.

Messages (3)
msg89060 - (view) Author: Evan Fosmark (efosmark) Date: 2009-06-07 22:07
Right now, it seems impossible to use cgi.FieldStorage in 3.0 if you're
giving it environ['wsgi.input'] like so:

    post_data = cgi.FieldStorage(
        fp=environ["wsgi.input"],
        environ=environ,
        keep_blank_values=True
        )


It gives the following error:

      File "/usr/local/lib/python3.0/cgi.py", line 489, in __init__
        self.read_urlencoded()
      File "/usr/local/lib/python3.0/cgi.py", line 589, in read_urlencoded
        self.strict_parsing):
      File "/usr/local/lib/python3.0/urllib/parse.py", line 377, in
parse_qsl
        pairs = [s2 for s1 in qs.split('&') for s2 in s1.split(';')]
TypeError: Type str doesn't support the buffer API
msg92621 - (view) Author: Michal Hordecki (MHordecki) Date: 2009-09-14 16:49
It is because FieldStorage requires str, whereas wsgi.input gives bytes.

You can always wrap environ['wsgi.input'] in TextIOWrapper.
msg139646 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2011-07-02 13:41
Closing as duplicate.  The other report has more discussion.
History
Date User Action Args
2011-07-02 13:41:13eric.araujosetstatus: open -> closed

superseder: WSGI, cgi.FieldStorage incompatibility

nosy: + eric.araujo
messages: + msg139646
resolution: duplicate
stage: resolved
2010-08-27 14:56:26BreamoreBoysetversions: + Python 3.1, Python 2.7, Python 3.2, - Python 3.0
2010-08-27 03:19:27floxsetnosy: + flox
2009-09-14 16:49:23MHordeckisetnosy: + MHordecki
messages: + msg92621
2009-06-15 21:32:23milescksetnosy: + milesck
2009-06-07 22:07:35efosmarkcreate