【问题标题】:Fail to authenticate with pydrive to google drive无法通过 pydrive 对谷歌驱动器进行身份验证
【发布时间】:2020-11-24 21:58:35
【问题描述】:

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

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

【问题讨论】:

    标签: python macos python-3.8 pydrive


    【解决方案1】:

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

    【讨论】:

    • 我也有这个问题,但我无法解决。你是说你可以通过添加这个步骤来解决它:``` gauth.LoadCredentialsFile("mycreds.txt") if gauth.credentials is None: # Authenticate if they are not there gauth.LocalWebserverAuth() elif gauth. access_token_expired: # 如果过期则刷新 gauth.Refresh() else: # 初始化保存的凭据 gauth.Authorize() # 将当前凭据保存到文件 gauth.SaveCredentialsFile("mycreds.txt") ```?
    猜你喜欢
    • 1970-01-01
    • 2020-01-24
    • 2021-12-26
    • 2012-04-01
    • 2014-01-05
    • 1970-01-01
    • 1970-01-01
    • 2023-03-13
    • 2016-06-17
    相关资源
    最近更新 更多