Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/347.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python urllib:如何在发出POST请求时在cert store中传递客户端安装的证书?_Python_Urllib - Fatal编程技术网

Python urllib:如何在发出POST请求时在cert store中传递客户端安装的证书?

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中模拟这一点(我必须使用客户端库,因此不使用请求) 这是我目前的代码:

这是我通常在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中模拟这一点(我必须使用客户端库,因此不使用请求)

这是我目前的代码:

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?任何例子都会大有帮助。不幸的是,我在网上找不到。