简体   繁体   English

该curl的等效请求命令

[英]Equivalent request command for this curl

I have a curl command which is working fine and uploading the file to the server. 我有一个curl命令,它可以正常工作并将文件上传到服务器。

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

I have tried the requests module in python. 我已经在python中尝试了请求模块。 The command I am issuing is 我发出的命令是

fileobj = open('dist\\test.zip', 'rb')
requests.put(__url, data={"upload": "upload"}, files={"archive": ("test.zip", fileobj)}, auth=HTTPBasicAuth(username,password))

the python request is not working and returning Bad Request , error 400 . python请求无法正常工作,并返回Bad Requesterror 400

What can be the equivalent python command ? 等效的python命令是什么?

I was able to figure out the solution to my problem. 我能够找出解决问题的方法。

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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM