gpt4 book ai didi

python - PyDrive 2.0 – 身份验证错误 : No code found in redirect

转载 作者:行者123 更新时间:2023-12-04 13:32:58 25 4
gpt4 key购买 nike

设置
我正在使用 PyDrive 2.0 连接到 Google Drive API。

def connect_google_drive_api():

import os

# use Gdrive API to access Google Drive
os.chdir('/Users/my/fol/ders/access_google_drive')
from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive

gauth = GoogleAuth()
gauth.LocalWebserverAuth() # client_secrets.json need to be in the same directory as the script
drive = GoogleDrive(gauth)

return drive
工作目录 /Users/mypath/access_google_drive包含 client_secrets.json ,看起来像,
{"web":{"client_id":"xxx","project_id":"invoice-creation-290413","auth_uri":"https://accounts.google.com/o/oauth2/auth","token_uri":"https://oauth2.googleapis.com/token","auth_provider_x509_cert_url":"https://www.googleapis.com/oauth2/v1/certs","client_secret":"xxx","redirect_uris":["http://localhost:8080/"],"javascript_origins":["http://localhost:8080"]}}
我在哪里更换了真正的 client_idclient_secretxxx .

问题
当浏览器 (Safari 14.0) 显示 Gdrive api link wants to access your Google Account然后我点击 Allow ,进程好像卡住了。
20秒左右后,显示以下错误,
Failed to find "code" in the query parameters of the redirect.
Try command-line authentication
Traceback (most recent call last):

File "<ipython-input-36-792f41ab7318>", line 1, in <module>
gauth.LocalWebserverAuth()

File "/opt/anaconda3/lib/python3.7/site-packages/pydrive2/auth.py", line 125, in _decorated
code = decoratee(self, *args, **kwargs)

File "/opt/anaconda3/lib/python3.7/site-packages/pydrive2/auth.py", line 273, in LocalWebserverAuth
raise AuthenticationError("No code found in redirect")

AuthenticationError: No code found in redirect
我该如何解决这个问题?

最佳答案

我正在导入 connect_google_drive_api()进入另一个脚本,说脚本 x.py .
两者connect_google_drive_api()功能和 x.py有线路 os.chdir('/Users/my/fol/ders/access_google_drive')将工作目录设置为 client_secrets.json 所在的位置曾是。
使用以下代码,我实际上建立了没有任何问题的连接,

def connect_google_drive_api():

# use Gdrive API to access Google Drive
from pydrive2.auth import GoogleAuth
from pydrive2.drive import GoogleDrive

gauth = GoogleAuth()
gauth.LocalWebserverAuth() # client_secrets.json need to be in the same directory as the script

drive = GoogleDrive(gauth)

return drive

关于python - PyDrive 2.0 – 身份验证错误 : No code found in redirect,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63955197/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com