此CURL命令的Python等效代码吗?

时间:2019-05-29 10:31:40

标签: python curl

下面是我的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编写相同的代码,有人可以通过请求库帮助我吗?我无法弄清楚如何在request.post

中添加--cert--cert-type
resp = requests.post(url, json = data, cert = (cert_path,cert_pass), verify = False)

1 个答案:

答案 0 :(得分:0)

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文件,以上代码有效。