I have a django server to download files, and when I use the browser, I can download the file without any problems.
But if I use the python-requests commands, this tells me that the CSRF check failed. Request aborted. The python request code is executed as follows:
file = {"docfile": open(fullfilename, "rb")}
s = requests.Session()
r = s.get(dhost)
r = s.post(dhost, files=file)
If I execute my code, I get the 403 code, and the CSRF error check failed. Request aborted. Reason identified for failure: CSRF token is missing or incorrect.
But if I look in the header that I sent, I have a set of cookies:
CaseInsensitiveDict({'Content-Length': u'84169',
'Accept-Encoding': 'gzip, deflate, compress',
'Accept': '*/*',
'User-Agent': 'python-requests/2.0.1 CPython/2.7.3 Linux/3.6.11+',
'Cookie': 'csrftoken=GOOIsG89i5oMCJO6594algTXooxoUeoL',
'Content-Type': 'multipart/form-data; boundary=86ada00b4f6c41d5997293cce7a53b6b'})
Could you tell me what I have to do to make this work?
Thanks,
John.
source
share