I have a django server to upload files and when I use a browser, I can upload the file without problems.
But if I use the python-requests commands, it tells me CSRF verification failed. Request aborted. The python-requests code is as followed:
# upload via HTTP
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 code 403
and the error CSRF verification failed. Request aborted. Reason given for failure:
CSRF token missing or incorrect.
But if I look in the header I sent, I have the cookie set:
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 please tell me what I should do in order to have this to work?