我正在尝试找出此问题的原因。我正在使用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
中失败的任何想法?非常感谢您的帮助,我在这里很困惑。