Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/322.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
REST请求中基于python证书的身份验证_Python_Rest_Authentication_Certificate - Fatal编程技术网

REST请求中基于python证书的身份验证

REST请求中基于python证书的身份验证,python,rest,authentication,certificate,Python,Rest,Authentication,Certificate,我试图用python向提供RESTAPI的给定服务器发送一个REST请求,该请求带有基于证书的身份验证,但经过数小时的搜索和尝试,我认为我需要帮助 我有来自上述服务器的签名证书和该证书的密钥。 服务器本身也提供https证书 我尝试了库httplib.HTTPSConnection: import httplib import urllib clientCert = "client.crt" clientKey = "client.key" serverCert

我试图用python向提供RESTAPI的给定服务器发送一个REST请求,该请求带有基于证书的身份验证,但经过数小时的搜索和尝试,我认为我需要帮助

我有来自上述服务器的签名证书和该证书的密钥。 服务器本身也提供https证书

我尝试了库httplib.HTTPSConnection:

import httplib import urllib clientCert = "client.crt" clientKey = "client.key" serverCert = 'server.crt' serverApi = "/api/getExample" serverHost = "restapi.example.com" serverPort = 443 requestMethod = "POST" params = urllib.urlencode({'someId': 'myId'}) headers = {"Content-type": "application/x-www-form-urlencoded","Accept": "application/json"} conn = httplib.HTTPSConnection(serverHost, serverPort, key_file=clientKey, cert_file=clientCert) conn.request(requestMethod, serverApi, params, headers) response = conn.getresponse() conn.getresponse() conn.close() 导入httplib 导入URL库 clientCert=“client.crt” clientKey=“client.key” serverCert='server.crt' serverApi=“/api/getExample” serverHost=“restapi.example.com” 服务器端口=443 requestMethod=“POST” params=urllib.urlencode({'someId':'myId'}) headers={“内容类型”:“应用程序/x-www-form-urlencoded”,“接受”:“应用程序/json”} conn=httplib.HTTPSConnection(服务器主机、服务器端口、密钥文件=clientKey、证书文件=clientCert) conn.request(requestMethod、serverApi、参数、头) response=conn.getresponse() conn.getresponse() 康涅狄格州关闭 我获取了
ssl.ssleror:ssl:CERTIFICATE\u VERIFY\u失败


有没有可能在该库中运行基于证书的身份验证?

我能够在“请求”库的帮助下运行它

导入json
导入请求
clientCrt=“cc.crt”
clientKey=“ck.key”
url=”https://example.com/api"
有效负载={“someId”:“myID”}
certServer='cs.crt'
headers={'content-type':'application/json'}
r=requests.post(url,data=json.dumps(有效负载),verify=certServer,
headers=headers,cert=(clientCrt,clientKey))
打印(r.状态\ U代码)
打印(r.json())
就这么简单