Question

I am trying to upload a file to django python server through python client.

I tried this -

import requests

url = 'http://wings.spectrumserver/sdm/lists'
files = {'file': open('file.ext', 'rb')}
r = requests.post(url, files=files)

but somehow it is not working. No error but no output/upload as well

I am successfully upload files by browser and command line.

curl -i --form docfile=@localfilename http://wings.spectrumserver/sdm/lists

Please suggest what to do ??

I do not know much about curl and python but maybe someone could suggest something which is replica of this curl command in pycurl as it is already working with curl.

Please refer here for more details about question -

upload file to django server using curl

Was it helpful?

Solution

I think the problem here is the name of file element. It should be docfile. In curl example you have passed that as docfile but in the python script you left it as file.

Alter this line:

files = {'file': open('file.ext', 'rb')}

to this:

files = {'docfile': open('file.ext', 'rb')}

OTHER TIPS

When you look at the request in your view you may see it in request.FILES['file'] I had a problem because I was had a bad setting in a headers file.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top