微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用Python登录到HP ALM时,证书验证失败

如何解决使用Python登录到HP ALM时,证书验证失败

我正在尝试创建一个仪表板,该仪表板将连接到HP ALM。 我现在要完成的工作是使用SSL证书通过Python对ALM进行基本身份验证。

ALM版本12.01

错误

HTTPSConnectionPool(host ='#####',port = ####):已超过最大重试次数 使用网址: #/ alm-authenticate?%3Calm-authentication%3E%3Cuser%3E #####%3C / user%3E%3Cpassword%3E ####%3C / password%3E%3C / alm-authentication%3E(引起通过SSLError(SSLCertVerificationError(1,'[SSL: CERTIFICATE_VERIFY_Failed]证书验证失败:无法获取 本地发行者证书(_ssl.c:1108)')))

这是我的代码:(某些部分被#代替以隐藏实际内容

FsstateBackend

输出

import ssl
import requests
import urllib3


#function to get certificate from server
def _certificate_required(hostname,port=443):
    pem_cert = ssl.get_server_certificate((hostname,port),ca_certs=None)
    print("Certificate string received")
    return pem_cert

urllib3.disable_warnings()
url = "http://##ALM-url##/qcbin/rest/is-authenticated/"
querystring = {"username":"##User##","password":"##pass##"}
headers = {
'token': "####",}
try:
    response = requests.request("GET",url,headers=headers,params=querystring,verify = "##/certificate.cer")
    print(response.headers)
    new_header = response.headers
    cert=_certificate_required(hostname="##ALM url##",port=443)
    print("Certicate string obtained from server:\n"+cert)
    with open('##/certificate.cer','w') as f:
        f.write(cert)

    print("Certificate updated")
    new_url ="https://##ALM url##/qcbin/authentication-point/alm-authenticate"
    response = requests.request("POST",new_url,headers=new_header,params="<alm-authentication><user>##USER##</user><password>##PASS##</password></alm-authentication>",verify = "##/certificate.cer")
    print(response.text)
    print(response.headers)
    print(response.status_code)
except Exception as e:
    print("Error occured")
    print(e)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。