【发布时间】:2023-03-13 04:38:01
【问题描述】:
解决方法: 因为我只需要访问电子表格,所以我使用 gspread 代替,oauth2 使用它要简单得多
我正在尝试使用 pydrive (python google drive api) 下载文件
我的代码为我工作,我没有改变任何东西,但现在它不会工作
我确保将文件公开(即使它是私有的也有效)
这是代码的相关部分:
gauth = GoogleAuth()
gauth.GetFlow()
# Try to load saved client credentials
gauth.LoadCredentialsFile("mycreds.txt")
if gauth.credentials is None:
# Authenticate if they're not there
gauth.LocalWebserverAuth()
elif gauth.access_token_expired:
# Refresh them if expired
gauth.flow.params.update({'access_type': 'offline'})
gauth.Refresh()
else:
# Initialize the saved creds
gauth.Authorize()
drive = GoogleDrive(gauth)
# Save the current credentials to a file
gauth.SaveCredentialsFile("mycreds.txt")
file1 = drive.CreateFile({'id': '1naQ4crE04nBmsj7yz4GNtmp-PKrCtfTHjl_AfGoTaws'})
file1.GetContentFile('Hello.csv', mimetype='text/csv')
这是我在控制台中遇到的错误:
pydrive.files.ApiRequestError: <HttpError 404 when requesting https://www.googleapis.com/drive/v2/files/1naQ4crE04nBmsj7yz4GNtmp-PKrCtfTHjl_AfGoTaws?alt=json returned "File not found: 1naQ4crE04nBmsj7yz4GNtmp-PKrCtfTHjl_AfGoTaws">
这就是上面的链接显示的内容:
{
"error": {
"errors": [
{
"domain": "usageLimits",
"reason": "dailyLimitExceededUnreg",
"message": "Daily Limit for Unauthenticated Use Exceeded.
Continued use requires signup.",
"extendedHelp": "https://code.google.com/apis/console"
}
],
"code": 403,
"message": "Daily Limit for Unauthenticated Use Exceeded. Continued
use requires signup."
}
}
感谢任何帮助,谢谢
【问题讨论】:
-
该错误意味着您的身份验证无法正常工作,可能未正确应用尝试此stackoverflow.com/questions/24419188/…
-
@DaImTo 这实际上是我用来创建自动身份验证过程的链接,问题是它曾经完美地运行了一天,而前一天就坏了,没有任何改变
-
检查 gauth.SaveCredentialsFile 与 drive = GoogleDrive(gauth) 的顺序。尝试删除文件并重新验证代码。
-
@DaImTo 尝试了几次,我总是成功验证(网页打开,我选择我的帐户并允许访问驱动器),仍然没有任何变化我应该检查一下我是否在高斯对象?
-
@pinoyyid 404 错误表示当前登录的用户无权访问文件 1naQ4crE04nBmsj7yz4GNtmp-PKrCtfTHjl_AfGoTaws 403 错误表示他没有登录这导致第一个 404 错误假设文件没有设为公开。这些错误可能并存。
标签: python google-api google-drive-api google-api-python-client pydrive