尝试使用 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') 是否意味着其他错误?