0

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

Community
  • 1
  • 1
Udit Gupta
  • 3,162
  • 11
  • 43
  • 71
  • I have the same problem. I look at the requests and there is nothing in there for request.FILES or request.POST – CrabbyPete Nov 21 '13 at 22:26

2 Answers2

1

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')}
scriptmonster
  • 2,741
  • 21
  • 29
0

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.

CrabbyPete
  • 505
  • 9
  • 18