Skip to content

Instantly share code, notes, and snippets.

@josuebrunel
Created December 18, 2017 14:11
Show Gist options
  • Save josuebrunel/3e9e421333a27902656ed7e0b776e7c8 to your computer and use it in GitHub Desktop.
Save josuebrunel/3e9e421333a27902656ed7e0b776e7c8 to your computer and use it in GitHub Desktop.
import cgi
def parse_form_data(formdata):
fp = cgi.StringIO(formdata)
env = cgi.os.environ
env['REQUEST_METHOD'] = 'POST'
data = cgi.FieldStorage(fp, environ=env)
return data
@josuebrunel
Copy link
Author

Here is an example

In [2]: fdata = 'user=toto&pass=toto'

In [3]: data = parse_form_data(fdata)

In [4]: data['user'].value
Out[4]: 'toto'

In [5]: data['pass'].value
Out[5]: 'toto'

In [6]: 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment