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)
但不知何故,它不工作。 没有错误,但没有输出/上传以及
but somehow it is not working. No error but no output/upload as well
我可以通过浏览器和命令行成功上传文件。 p>
I am successfully upload files by browser and command line.
curl -i --form docfile=@localfilename http://wings.spectrumserver/sdm/lists
请建议做什么?
我不太了解卷曲和python,但也许有人可以在 pycurl
中提出这个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脚本中,将其作为文件
。
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屋!