当尝试使用httplib2进行HTTPS GET时,我收到以下错误。
>>> import httplib2
>>> http = httplib2.Http(cache=None, timeout=30)
>>> response, content = http.request('https://www.example.com', 'GET')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/app/jython/2.5.2/Lib/site-packages/httplib2/__init__.py", line 1436, in request
(response, content) = self._request(conn, authority, uri, request_uri, method, body, headers, redirections, cachekey)
File "/app/jython/2.5.2/Lib/site-packages/httplib2/__init__.py", line 1188, in _request
(response, content) = self._conn_request(conn, request_uri, method, body, headers)
File "/app/jython/2.5.2/Lib/site-packages/httplib2/__init__.py", line 1162, in _conn_request
conn.connect()
File "/app/jython/2.5.2/Lib/site-packages/httplib2/__init__.py", line 925, in connect
raise socket.error, msg
socket.sslerror: (-1, 'SSL exception')
我对SSL不太熟悉,不熟悉-1错误代码的含义。我假设httplib2不验证SSL证书。
常规wget失败,但wget --no-check-cert有效。
$ wget -qO- https://www.example.com --no-check-certificate
Up
通过浏览器访问URL似乎也可以正常工作。我在代码中做错了吗?或者socket.sslerror:( - 1,'SSL exception')是否意味着其他错误?
答案 0 :(得分:1)
SSL支持取决于底层套接字模块。在这种情况下,您似乎确实有ssl支持。您可以使用...
禁用它http = httplib2.Http(cache=None, timeout=30, disable_ssl_certificate_validation=True)