jQuery文件上传:cURL文件上传正常,Python请求不成功

时间:2019-07-19 05:03:17

标签: php python curl python-requests jquery-file-upload

我正在尝试找出此问题的原因。我正在使用requests通过文件上传器https://github.com/blueimp/jQuery-File-Upload来发布文件

我正在运行Ubuntu 16.04 LTS发送POST

在我的CLI上运行此程序非常正常:

curl -F "files=@test.txt" https://example.com/jqu/index.php

并返回:

{
   "files":[
      {
         "name":"61a250036a881080db16a00827d41d53.txt",
         "size":2,
         "type":"text\/plain",
         "niceSize":"2 B",
         "realName":"test.txt",
         "delFileKey":"4d88ea9cced859c521927d3725710518",
         "fileKey":"f804e7d6214d16212c03dcde176102ba",
         "delete_url":"https:\/\/example.com\/jqu\/?file=61a250036a881080db16a00827d41d53.txt",
         "delete_type":"DELETE"
      }
   ]
}

requests中尝试相同的操作失败:

files = {
    'files': ('test.txt', open('test.txt', 'rb')),
}

upload = requests.post('https://example.com/jqu/index.php', files=files).json()
{
   'error':"File wasn't successfully moved/upped.",
   'size':False,
   'niceSize':'0 B',
   'delete_url':'https://example.com/jqu/?file=85f2023603e8dc9bbee557b80f4cd779.',
   'name':'85f2023603e8dc9bbee557b80f4cd779.',
   'type':'multipart/form-data',
   'delete_type':'DELETE',
   'realName':None
}

关于为什么它可以在cURL中运行但在requests中失败的任何想法?非常感谢您的帮助,我在这里很困惑。

0 个答案:

没有答案