python请求模块无法在django服务器上上传文件 [英] python requests module not able to upload file on django server
问题描述
我试图通过python客户端将文件上传到django python服务器。
I am trying to upload a file to django python server through python client.
我试过了 -
import requests
url = 'http://wings.spectrumserver/sdm/lists'
files = {'file': open('file.ext', 'rb')}
r = requests.post(url, files=files)
$ b b
但不知何故,它不工作。 没有错误,但没有输出/上传
我已成功通过浏览器和命令行上传文件。 p>
I am successfully upload files by browser and command line.
curl -i --form docfile=@localfilename http://wings.spectrumserver/sdm/lists
请建议做什么?
我不太了解curl和python,但也许有人可以建议在 pycurl
中的curl命令的副本,因为它已经在使用curl。
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 -
推荐答案
这里是文件元素的名称。应该是 docfile
。在curl示例中,你已经传递了 docfile
,但是在python脚本中你把它作为 file
。
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
.
更改此行:
files = {'file': open('file.ext', 'rb')}
到此:
files = {'docfile': open('file.ext', 'rb')}
这篇关于python请求模块无法在django服务器上上传文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!