gpt4 book ai didi

python-requests 等同于 curl 的 --data-binary?

转载 作者:太空宇宙 更新时间:2023-11-03 12:08:30 25 4
gpt4 key购买 nike

Curl 有一个选项可以按原样发送文件 --data-binary option .

测试 Qualys WAS API 时,以下 curl 命令有效:

curl -u "username:password" -H "content-type: text/xml" -X "POST" --data-binary @- "https://qualysapi.qualys.com/qps/rest/3.0/search/was/webapp" < post.xml

post.xml:

<ServiceRequest><filters><Criteria operator="CONTAINS" field="name">PB - </Criteria></filters></ServiceRequest>

使用 Python 的请求模块,我不断收到 HTTPError: 415 Client Error: Unsupported Media Type。

import requests
url = 'https://qualysapi.qualys.com/qps/rest/3.0/search/was/webapp'
payload = '<ServiceRequest><filters><Criteria operator="CONTAINS" field="name">PB - </Criteria></filters></ServiceRequest>'
headers = {'X-Requested-With': 'Python requests', 'Content-type': 'application/json'}
r = requests.post(url, data=payload, headers=headers, auth=('username', 'password'))

尝试提交文件文件参数时,同样以 415 错误结束。

import requests
url = 'https://qualysapi.qualys.com/qps/rest/3.0/search/was/webapp'
payload = '<ServiceRequest><filters><Criteria operator="CONTAINS" field="name">PB - </Criteria></filters></ServiceRequest>'
headers = {'X-Requested-With': 'Python requests', 'Content-type': 'application/json'}
r = requests.post(url, data=payload, headers=headers, auth=('username', 'password'))

我设置它的原因是将其合并到 qualysapi Python package 中.

最佳答案

原来我应该拥有的标题是

headers = {'X-Requested-With': 'Python requests', 'Content-type': 'text/xml'}

关于python-requests 等同于 curl 的 --data-binary?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17680688/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com