【问题标题】:Python https connection using self-signed cert使用自签名证书的 Python https 连接
【发布时间】:2016-01-07 21:15:13
【问题描述】:

我正在尝试从 python 脚本中实现 SSL。我通过浏览页面并接受自签名证书获得了证书。然后我将它从 Firefox 中导出,并以 .pem 格式保存到我的桌面。

代码是:

sslcertlocation = '/Users/derjur/Desktop/MYHOST.mydomain.local.pem'

idpentryurl = 'https://MYHOST.mydomain.local:443/adfs/ls/IdpInitiatedSignOn.aspx?loginToRp=urn:amazon:webservices'

session = requests.Session()

response = session.get(idpentryurl, verify=sslcertlocation)

错误是:

requests.exceptions.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:590)

MYHOST 在 Windows 2008 R2 下运行 iis7。完整的脚本基于此博客中描述的 SAML/ADFS 脚本: http://blogs.aws.amazon.com/security/post/Tx1LDN0UBGJJ26Q/How-to-Implement-Federated-API-and-CLI-Access-Using-SAML-2-0-and-AD-FS#postCommentsTx1LDN0UBGJJ26Q

脚本的非 SSL 部分按预期工作。有趣的是,cmets 中没有人提到 SSL...

【问题讨论】:

    标签: python amazon-web-services ssl adfs


    【解决方案1】:

    我认为您设置了错误的参数。根据 requests.Session(),get() 将 verify 的可选参数 - 一个布尔值 - 发送到 request()。

    根据request.Session().request(),传递你的证书的参数是cert=/path/to/cert.pem,它也被检查为字符串是路径或元组是(证书,密钥)对。

    【讨论】:

    • 我已将行修改为response = session.get(idpentryurl, cert=sslcertlocation),错误已更改为requests.exceptions.SSLError: [SSL] PEM lib (_ssl.c:2600)。是否有可能我使用了错误类型的证书?
    • 转换为 .crt(使用 openssl x509 -outform der -in MYHOST.mydomain.local.pem -out MYHOST.mydomain.local.crt )将错误更改为 requests.exceptions.SSLError: [SSL] PEM lib (_ssl.c:2581)
    猜你喜欢
    • 2012-12-31
    • 2014-08-05
    • 1970-01-01
    • 2023-03-02
    • 2017-02-19
    • 1970-01-01
    • 2014-05-16
    • 1970-01-01
    • 2014-11-01
    相关资源
    最近更新 更多