小编sci*_*ris的帖子

python请求文件上传

我正在执行一个使用Python请求库上传文件的简单任务.我搜索了Stack Overflow,似乎没有人遇到同样的问题,即服务器没有收到该文件:

import requests
url='http://nesssi.cacr.caltech.edu/cgi-bin/getmulticonedb_release2.cgi/post'
files={'files': open('file.txt','rb')}
values={'upload_file' : 'file.txt' , 'DB':'photcat' , 'OUT':'csv' , 'SHORT':'short'}
r=requests.post(url,files=files,data=values)
Run Code Online (Sandbox Code Playgroud)

我正在用我的文件名填充'upload_file'关键字的值,因为如果我把它留空,它会说

Error - You must select a file to upload!
Run Code Online (Sandbox Code Playgroud)

现在我明白了

File  file.txt  of size    bytes is  uploaded successfully!
Query service results:  There were 0 lines.
Run Code Online (Sandbox Code Playgroud)

仅当文件为空时才会出现.所以我不知道如何成功发送我的文件.我知道该文件有效,因为如果我去这个网站并手动填写表格,它会返回一个很好的匹配对象列表,这就是我所追求的.我非常感谢所有提示.

其他一些线程相关(但没有回答我的问题):

python file-upload file python-requests

93
推荐指数
4
解决办法
15万
查看次数

标签 统计

file ×1

file-upload ×1

python ×1

python-requests ×1