使用 google-api-python-client init() 方法时出现 SSL 错误

SSL error when using google-api-python-client init() method

你好,

我在使用 google-api-python-客户端时遇到 SSL 错误。调用 sample_tools.init() 获取服务对象会触发错误。在我重新安装 Kubuntu 并更新到 python 3.8(来自 3.6.10)之前,这是有效的。

我有 googled 但我找不到这个确切的错误。我尝试更新库的版本,但没有用,又回到了旧版本。鉴于我不知道该尝试什么,欢迎提供任何帮助、文档或资源。

我还尝试使用 pyenv 为 3.8.2 安装 python 并按照 here 所述安装了 python3-openssl 和 libssl-dev,然后是PyCharm 里面的 virtualenv 和那个 python。运气不好。

这是回溯:

Traceback (most recent call last):
  File "/home/madtyn/PycharmProjects/alfredBot/my_bot.py", line 427, in main
    reload_credentials()
  File "/home/madtyn/PycharmProjects/alfredBot/apis/blogger/blogger_insert.py", line 84, in reload_credentials
    service, flags = sample_tools.init(
  File "/home/madtyn/venvs/alfred38/lib/python3.8/site-packages/googleapiclient/sample_tools.py", line 90, in init
    credentials = tools.run_flow(flow, storage, flags)
  File "/home/madtyn/venvs/alfred38/lib/python3.8/site-packages/oauth2client/_helpers.py", line 133, in positional_wrapper
    return wrapped(*args, **kwargs)
  File "/home/madtyn/venvs/alfred38/lib/python3.8/site-packages/oauth2client/tools.py", line 243, in run_flow
    credential = flow.step2_exchange(code, http=http)
  File "/home/madtyn/venvs/alfred38/lib/python3.8/site-packages/oauth2client/_helpers.py", line 133, in positional_wrapper
    return wrapped(*args, **kwargs)
  File "/home/madtyn/venvs/alfred38/lib/python3.8/site-packages/oauth2client/client.py", line 2053, in step2_exchange
    resp, content = transport.request(
  File "/home/madtyn/venvs/alfred38/lib/python3.8/site-packages/oauth2client/transport.py", line 280, in request
    return http_callable(uri, method=method, body=body, headers=headers,
  File "/home/madtyn/venvs/alfred38/lib/python3.8/site-packages/httplib2/__init__.py", line 1322, in request
    (response, content) = self._request(conn, authority, uri, request_uri, method, body, headers, redirections, cachekey)
  File "/home/madtyn/venvs/alfred38/lib/python3.8/site-packages/httplib2/__init__.py", line 1072, in _request
    (response, content) = self._conn_request(conn, request_uri, method, body, headers)
  File "/home/madtyn/venvs/alfred38/lib/python3.8/site-packages/httplib2/__init__.py", line 995, in _conn_request
    conn.connect()
  File "/usr/lib/python3.8/http/client.py", line 1409, in connect
    self.sock = self._context.wrap_socket(self.sock,
  File "/usr/lib/python3.8/ssl.py", line 500, in wrap_socket
    return self.sslsocket_class._create(
  File "/usr/lib/python3.8/ssl.py", line 1040, in _create
    self.do_handshake()
  File "/usr/lib/python3.8/ssl.py", line 1309, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLError: [SSL] internal error (_ssl.c:1108)

看来,Google 日历中也存在同样的问题。 Google 日历 github 存储库中提交了一个未解决的错误。 解决此问题可能需要一些时间。

参考:https://github.com/home-assistant/core/issues/35870

目前,您可以在同一台机器上安装多个 python 版本。如果您通过安装它们,请从源代码方法编译。在安装时使用 make altinstall。这样您就可以将以前工作的 python 版本指向您的应用程序并完成它。解决后,您可以切换回较新的版本。