New submission from Daniel Klein <daniel.v.kl...@gmail.com>:

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.

----------
components: Library (Lib)
messages: 320597
nosy: Daniel Klein
priority: normal
severity: normal
status: open
title: cgi.FieldStorage doesn't parse QUERY_STRING with POST that is not 
application/x-www-form-urlencoded
type: behavior
versions: Python 2.7

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue33982>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to