[Answer]-Feed django web server with desktop program data

1👍

The best way is to use the csrf cookie sent by django and send it back via a http header when you’re posting some data:

>>> session = requests.Session()
>>> # get the cookie
>>> resp = session.get(url)
>>> # post data with csrf header using the cookie value
>>> resp = session.post(url, data=data, headers={"X-CSRFToken": resp.cookies['csrftoken'])

This way you don’t have to parse the html result to get the csrf token or to modify the data sent.

👤gawel

Leave a comment