Python urllib:如何在发出POST请求时在cert store中传递客户端安装的证书?
这是我通常在powershell中发出POST请求的操作:Python urllib:如何在发出POST请求时在cert store中传递客户端安装的证书?,python,urllib,Python,Urllib,这是我通常在powershell中发出POST请求的操作: Invoke-RestMethod -uri $url -Method Post -Body $body -ContentType 'application/json' -Certificate (ls Cert:\CurrentUser\my |Where {$_.subject -eq "CN=mycertname"}) 我正试图使用urllib在python中模拟这一点(我必须使用客户端库,因此不使用请求) 这是我目前的代码:
Invoke-RestMethod -uri $url -Method Post -Body $body -ContentType 'application/json' -Certificate (ls Cert:\CurrentUser\my |Where {$_.subject -eq "CN=mycertname"})
我正试图使用urllib在python中模拟这一点(我必须使用客户端库,因此不使用请求)
这是我目前的代码:
url = "https://x"
body = {
"x": {"x": "x" }
}
params = json.dumps(body).encode('utf8')
req = urllib.request.Request(url, data=params,
headers={'content-type': 'application/json'})
response = urllib.request.urlopen(req)
print(response.read().decode('utf8'))
我无法找到如何使用urllib在powershell脚本中传递客户端证书,正如上面所做的那样?您是否查看了urllib.request.urlopen()的capath和cafile参数?是的,但是我不能让它工作。如何定义指向Windows上证书存储的capath?任何例子都会大有帮助。不幸的是,我在网上找不到。