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

4

2 回答 2

1

我认为这里的问题是文件元素的名称。应该是docfile。在 curl 示例中,您已将其传递为 asdocfile但在 python 脚本中您将其保留为file.

改变这一行:

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

对此:

files = {'docfile': open('file.ext', 'rb')}
于 2013-11-08T08:40:48.347 回答
0

当您在视图中查看请求时,您可能会在 request.FILES['file'] 中看到它我遇到了问题,因为我在头文件中的设置错误。

于 2013-11-22T00:14:50.140 回答