You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Python发送SOAP请求遇CertificateError及SSL相关问题求助

求助:Python requests发送SOAP请求时的SSL证书验证问题

我需要用Python的requests库向SOAP接口发送XML请求,最初写了这段代码:

response = requests.post(url, data=body, headers=headers)

发送后遇到了SSL验证失败的错误:

requests.exceptions.SSLError: HTTPSConnectionPool(host='49.1.92.38', port=7911): Max retries exceeded with url: /ECARE/CRMInterface_INV_Services (Caused by SSLError(SSLError("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')],)",),))

我试着在请求里加上verify=False跳过验证:

response = requests.post(url, data=body, headers=headers, verify=False)

但收到了类似you can't send a request like that的错误提示,显然服务器要求必须验证证书才能请求。

我手头有.cer和.crt格式的证书文件,于是尝试用cert参数传入证书对:

response = requests.post(url, data=body, headers=headers, cert=(c1, c2))

结果又出现了OpenSSL格式相关的错误:

OpenSSL.SSL.Error: [('PEM routines', 'PEM_read_bio', 'no start line'), ('SSL routines', 'SSL_CTX_use_PrivateKey_file', 'PEM lib')]

更新:
我用OpenSSL命令把.cer转换成了PEM格式:

openssl x509 -inform der -in PK.cer -out PK.pem

然后把转换后的证书传入verify参数:

response = requests.post(url, data=body, headers=headers, verify='PK.pem')

这次的错误变成了主机名不匹配:

requests.exceptions.SSLError: HTTPSConnectionPool(host='49.1.92.38', port=7911): Max retries exceeded with url: /ECARE/CRMInterface_INV_Services (Caused by SSLError(CertificateError("hostname '49.1.92.38' doesn't match 'crm.at.com'",),))

我尝试了各种方法,但始终没法成功通过证书验证发送SOAP请求,希望各位能给我一些技术上的帮助,谢谢!

内容的提问来源于stack exchange,提问作者MasOOd.KamYab

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 10:37:08