这个CURL命令的Python等效代码?

2024-03-28 22:13:24 发布

您现在位置:Python中文网/ 问答频道 /正文

下面是我的CURL命令:

curl -v -X POST --cert ~/Desktop/cert/hardening.qa.pkcs:0JMQqqksE7Q2 --cert-type p12 https://somewebsite.com/SomeServers/PublishQueue/a.qa.queue.z -d'[{"count":5,"requeue":true,"encoding":"auto","truncate":50000}]'

证书文件为:~/Desktop/cert/hardening.qa.pkcs 证书密码:0JMQqqksE7Q2

我需要用Python编写相同的代码,有人能帮我处理请求库吗。我不知道如何在requests.post中添加--cert--cert-type

resp = requests.post(url, json = data, cert = (cert_path,cert_pass), verify = False)

Tags: https命令certtypecurlqapostrequests
1条回答
网友
1楼 · 发布于 2024-03-28 22:13:24
import requests

if __name__=='__main__':
    url='https://somewebsite.com/SomeServers/PublishQueue/a.qa.queue.z'
    data=[{"table":"A","count":500},{"table":"B","count":1500}]
    cert_path='~/hardening.qa.pem'
    resp=requests.post(url,json=data,cert=cert_path)
    print(resp.status_code)
    print(resp.text)
    print(resp.headers)

问题是证书是P12格式的,我将其转换为.pem文件,上面的代码正常工作

相关问题 更多 >