我想将XML
发送到我使用python请求的soap请求,如下所示:
response = requests.post(url, data=body, headers=headers)
当我发送请求时,我提出此请求:
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
个文件要发送,但我这样发送:
response = requests.post(url, data=body, headers=headers, cert=(c1, c2))
并收到此错误:
OpenSSL.SSL.Error: [('PEM routines', 'PEM_read_bio', 'no start line'), ('SSL routines', 'SSL_CTX_use_PrivateKey_file', 'PEM lib')]
更新:
我使用openssl x509 -inform der -in PK.cer -out PK.pem
并试试这个:
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'",),))
我想用这个证书文件发送这个肥皂请求,但我找不到任何有用的东西。 谁能帮助我?
问候。
答案 0 :(得分:0)
这里有几个问题:
...证书验证失败......
response = requests.post(url, data=body, headers=headers, verify=False)
我提出了一些错误,例如
you can't send a request like that
。
首先,设置verify=False
是个坏主意,因为这会完全禁用证书验证(即不安全)。但是,您现在不会收到SSL错误,但会出现其他错误。这意味着它成功进行了SSL握手(没有证书验证)
您看到的错误可能是因为服务器不喜欢您的请求。既然不知道服务器究竟想要什么以及你发送了什么,就不可能在这里说出你做错了什么。
response = requests.post(url, data=body, headers=headers, cert=(c1, c2))
并收到此错误:
OpenSSL.SSL.Error: [('PEM routines', 'PEM_read_bio', 'no start line'), ('SSL routines', 'SSL_CTX_use_PrivateKey_file', 'PEM lib')]
这是因为您已使用cert
参数clearly documented用于客户端证书,即证书和匹配的私钥。它看起来不像你这样的客户证书。我不确定您尝试使用的文件的内容是什么(“我有.cer和.crt文件”没有说明内容)但是如果您尝试将这些文件用作CA您需要使用verify parameter代替。