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.

classification
Title: cgi.FieldStorage doesn't parse QUERY_STRING with POST that is not application/x-www-form-urlencoded
Type: behavior Stage:
Components: Library (Lib) Versions: Python 2.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Daniel Klein
Priority: normal Keywords:

Created on 2018-06-27 16:06 by Daniel Klein, last changed 2022-04-11 14:59 by admin.

Messages (1)
msg320597 - (view) Author: Daniel Klein (Daniel Klein) Date: 2018-06-27 16:06
The documentation says "A form submitted via POST that also has a query string will contain both FieldStorage and MiniFieldStorage items." suggesting that I can have a query with bost a QUERY_STRING and POST parameters. The code backs this up most of the time...

In read_urlencoded() the initial query string is read from STDIN, and self.qs_on_post (i.e., env['QUERY_STRING']) is appended to that. This is what is called when the CONTENT_TYPE of the POST request is application/x-www-form-urlencoded. This leads to a FieldStorage object containing a list of MiniFieldStorage objects, like:

FieldStorage(None, None, [MiniFieldStorage('action', 'rate'), MiniFieldStorage('seq', '3'), MiniFieldStorage('version', '15')])


However, I am using a webhook interface from Google cloud, and it (legitimately!) does a POST with a CONTENT_TYPE of application/json.

When I call cgi.Fieldstorage(), the __init__ routine ultimately calls read_single().  This results in a FieldStorage object containing a single string as 

FieldStorage(None, None, '{"incident": {"incident_id": "0.ktptjso969s0","res...the rest of the JSON')

This results in a few problems.
1) The QUERY_STRING args are not parsed as promised
2) The FeildStorage object does not contain a list, and so will raise TypeError, "not indexable" if I try to use most of the other FieldStorage methods.
History
Date User Action Args
2022-04-11 14:59:02adminsetgithub: 78163
2018-06-27 16:06:08Daniel Kleincreate