下面是我的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)
答案 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文件,以上代码有效。