无法使用 pydrive 对 google 驱动器进行身份验证

Fail to authenticate with pydrive to google drive

我按照本文档中的说明使用 PyDrive link 在 运行 这部分之后

from pydrive.auth import GoogleAuth

gauth = GoogleAuth()
gauth.LocalWebserverAuth() # Creates local webserver and auto handles authentication.

似乎一切正常,我的浏览器打开了,我需要使用我的 Gmail 帐户进行身份验证。但是在接受最后一部分之后,进程加载并且我在浏览器中收到一条错误消息 Safari Screenshot 它是德语,基本上是说 safari 无法连接到 localhost:8080。

在终端中我得到这个 Traceback:

Failed to find "code" in the query parameters of the redirect.
Try command-line authentication
Traceback (most recent call last):
  File "/Users/gepluse/CodeProjects/ComunioBuster/test2.py", line 4, in <module>
    gauth.LocalWebserverAuth()  # Creates local webserver and auto handles authentication.
  File "/Users/gepluse/CodeProjects/ComunioBuster/venv/lib/python3.8/site-packages/pydrive/auth.py", line 115, in _decorated
    code = decoratee(self, *args, **kwargs)
  File "/Users/gepluse/CodeProjects/ComunioBuster/venv/lib/python3.8/site-packages/pydrive/auth.py", line 241, in LocalWebserverAuth
    raise AuthenticationError('No code found in redirect')
pydrive.auth.AuthenticationError: No code found in redirect

我也跟着这个教程link检查了我做的每一步都没有成功。

在此处的某些帖子中,防火墙是问题所在,但我 Mac 上的防火墙未激活。

我是 运行 macOS 10.15.7 / Python 3.8.3 / PyDrive 1.3.1

我根据 Dano 的 Solution 进行了修改。 mycreds.txt 的保存和加载帮助解决了这个问题。