简体   繁体   English

Curl 命令等效于 Python(请求)

[英]Curl Command Equivalent in Python (requests)

What could be the Python equivalent code (requests library) to the following CURL command?以下 CURL 命令的 Python 等效代码(请求库)可能是什么?

curl -i -x POST -H "content-type: multipart/form-data" -F file = abc.txt http://localhost:xxxx/ -F 'params= { "key1": "val1", "key2": "val2" }'

you can use requests library you need to install requests library and after that您可以使用您需要安装请求库的请求库,然后

import requests
params = { 'key1': 'val1', 'key2': 'val2'}
headers = {'content-type': 'multipart/form-data'}
files = {'file': open('abc.txt', 'rb')}
r = requests.post('your_link', params=params, headers=headers, files=files)

For more information you can use https://requests.readthedocs.io/en/master/user/quickstart/有关更多信息,您可以使用https://requests.readthedocs.io/en/master/user/quickstart/

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

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