python - httplib2 socket.sslerror : (-1, 'SSL exception' )

标签 python ssl jython

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

最佳答案

SSL 支持取决于您的底层套接字模块。在这种情况下,您似乎确实有 ssl 支持。您可以使用...禁用它

http = httplib2.Http(cache=None, timeout=30, disable_ssl_certificate_validation=True)

关于python - httplib2 socket.sslerror : (-1, 'SSL exception' ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11532966/

相关文章:

python - 使用 lIst 中的字符串值进行 bool 表达式的问题

Python:忽略 elementtree.ElementTree 中的 xmlns

javax.net.ssl.SSLHandshakeException HttpsURLConnection

python GUI 与 Swing 相比?

python - HTTPS 使用 Jython

python - Django Manager 的顺序会影响哪些功能?

python - python django View 中的错误

apache - 并行支持两个端口的 SSL 在静态编译的 Apache2 二进制文件中不起作用

c# - 使用 HttpClientCertificate 与 X509Certificate2 检查证书有效性

python - makeQuicktimeMovie 可以用于 png 文件吗?