我们使用developers.google.com创建了api用户,并将凭据下载为json文件。 现在在我的macbook上,gspread身份验证在使用credentials.json时运行良好。当在aws上将相同的配置移动到linux服务器时,它会给出403个权限不足错误。
Pip和python版本相同。
异常
gspread.v4.exceptions.APIError: {
"error": {
"errors": [
{
"domain": "global",
"reason": "insufficientPermissions",
"message": "Insufficient Permission"
}
],
"code": 403,
"message": "Insufficient Permission"
}
}
基本代码
import gspread
from oauth2client.service_account import ServiceAccountCredentials
scope = ['https://spreadsheets.google.com/feeds']
creds = ServiceAccountCredentials.from_json_keyfile_name('credentials.json', scope)
client = gspread.authorize(creds)
sheet = client.open('MySheetName').sheet1
尝试将
scope
变量更改为以下值:确保在API控制台中启用了驱动器API。
gspread已经升级,现在它基于API v4。虽然速度更快,但需要在作用域中进行更新。
这里有同样的问题:https://github.com/burnash/gspread/issues/512
您似乎正在使用服务帐户。为了让服务帐户访问您的sperad工作表,它需要访问它。
确保您与服务帐户电子邮件地址共享工作表,您可以通过google drive网页执行此操作
如果更新作用域后仍无法访问,请尝试在终端中运行此命令:
相关问题 更多 >
编程相关推荐