[Tutor] cgi module help

Peter Otten __peter__ at web.de
Tue Aug 13 11:49:36 EDT 2019


rmlibre at riseup.net wrote:

> I have a question about the cgi module.
> 
> I'm trying to retrieve post data as a nested dictionary from client
> code.
> 
> For instance:
> 
> 
> 
> """client code"""
> from requests import sessions
> from datetime import datetime
> 
> session = sessions.Session()
> date = str(datetime.now())
> msg_id = 0001
> message = {"metadata": {"date": date, "id": msg_id}}
> session.post(data=message)

I made the above post to the server I found here

https://gist.github.com/mdonkers/63e115cc0c79b4f6b8b3a6b797e485c7

and got the following output:


$ python3 server.py 8080
INFO:root:Starting httpd...

INFO:root:POST request,
Path: /
Headers:
Host: localhost:8080
Content-Length: 25
Content-Type: application/x-www-form-urlencoded
Accept-Encoding: gzip, deflate, compress
Accept: */*
User-Agent: python-requests/2.2.1 CPython/2.7.6 Linux/3.13.0-170-generic



Body:
metadata=date&metadata=id

127.0.0.1 - - [13/Aug/2019 17:45:35] "POST / HTTP/1.1" 200 -

It looks like the data doesn't even get through.




More information about the Tutor mailing list