我正在使用httplib2打开ssl连接。以下是代码。

import httplib2

if __name__=='__main__':
    conn = httplib2.Http(disable_ssl_certificate_validation=True)
    conn.add_certificate('serverkey.pem', 'servercert.pem', '')
    resp, content = conn.request(uri = 'https://xxx.xxx.xxx.xxx:xxxx/Konfigurator
                   /REST/login?userName=xxx&pass=xxx', method = 'POST')
    print resp

这是我得到的错误。
Traceback (most recent call last):
File "C:\eclipse-workspace\REST\src\examples.py", line 7, in <module>
resp, content = conn.request(uri = 'https://xxx.xxx.xxx.xxx:xxx/Konfigurator/REST/login?userName=xxx&pass=xxx', method = 'POST')
File "C:\Python27\lib\site-packages\httplib2-0.7.1-py2.7.egg\httplib2\__init__.py", line 1437, in request
(response, content) = self._request(conn, authority, uri, request_uri, method, body, headers, redirections, cachekey)
 File "C:\Python27\lib\site-packages\httplib2-0.7.1-py2.7.egg\httplib2\__init__.py", line 1189, in _request
(response, content) = self._conn_request(conn, request_uri, method, body, headers)
 File "C:\Python27\lib\site-packages\httplib2-0.7.1-py2.7.egg\httplib2\__init__.py", line 1163, in _conn_request
conn.connect()
File "C:\Python27\lib\site-packages\httplib2-0.7.1-py2.7.egg\httplib2\__init__.py", line 925, in connect
raise socket.error, msg
socket.error: [Errno 10054] An existing connection was forcibly closed by the remote host

代码正确吗?还是我在这里遗漏了一些东西?

最佳答案

我知道了问题是服务器仅支持TLSv1和SSLv3加密。如果未指定版本,则httplib2模块默认为SSLv23。这导致服务器以RST数据包响应。可能是他们代码中的错误。在他们的初始 .py中进行了更改,在wrap_socket函数中包含了“ssl_version = 3”(对于TLS为3),它可以正常工作。

关于python - 使用httplib2打开ssl连接时出错,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/8007348/

10-13 02:48