该curl的等效请求命令

时间:2018-07-06 15:16:31

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

我有一个curl命令,可以正常工作,并将文件上传到服务器。

SELECT ad.listingId
FROM   advalues ad
JOIN   advalues ad2
  ON ad.listingId = ad2.listingId
WHERE ( ad.identifier  = 'activity' AND ad.value  IN( 'Mellem', 'Højt' ) )
 AND  ( ad2.identifier = 'race'     AND ad2.value IN( 'Alaskan Husky' ) ) 

我已经在python中尝试了请求模块。我发出的命令是

curl -v <url> --fail --user <username>:<password> --upload-file filename

python请求无法正常工作,并返回fileobj = open('dist\\test.zip', 'rb') requests.put(__url, data={"upload": "upload"}, files={"archive": ("test.zip", fileobj)}, auth=HTTPBasicAuth(username,password)) Bad Request

什么是等效的python命令?

1 个答案:

答案 0 :(得分:2)

我能够找出解决问题的方法。

zip_file = open(os.path.join(root, file), 'rb')
headers = {'content-type': 'application/zip'}
return_val = requests.put(url=url, data=zip_file, auth=HTTPBasicAuth(username, password),headers=header_type)