Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cgi.FieldStorage doesn't parse QUERY_STRING with POST that is not application/x-www-form-urlencoded #78163

Closed
DanielKlein mannequin opened this issue Jun 27, 2018 · 2 comments
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@DanielKlein
Copy link
Mannequin

DanielKlein mannequin commented Jun 27, 2018

BPO 33982

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = None
created_at = <Date 2018-06-27.16:06:08.351>
labels = ['type-bug', 'library']
title = "cgi.FieldStorage doesn't parse QUERY_STRING with POST that is not application/x-www-form-urlencoded"
updated_at = <Date 2018-06-27.16:06:08.351>
user = 'https://bugs.python.org/DanielKlein'

bugs.python.org fields:

activity = <Date 2018-06-27.16:06:08.351>
actor = 'Daniel Klein'
assignee = 'none'
closed = False
closed_date = None
closer = None
components = ['Library (Lib)']
creation = <Date 2018-06-27.16:06:08.351>
creator = 'Daniel Klein'
dependencies = []
files = []
hgrepos = []
issue_num = 33982
keywords = []
message_count = 1.0
messages = ['320597']
nosy_count = 1.0
nosy_names = ['Daniel Klein']
pr_nums = []
priority = 'normal'
resolution = None
stage = None
status = 'open'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue33982'
versions = ['Python 2.7']

@DanielKlein
Copy link
Mannequin Author

DanielKlein mannequin commented Jun 27, 2018

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.

@DanielKlein DanielKlein mannequin added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Jun 27, 2018
@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
@kumaraditya303
Copy link
Contributor

Closing as cgi module is deprecated as per PEP 594 and further no improvements or bug fixes will be made to the module.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

1 participant