问题描述
使用developers.google.com,我们创建了api用户并下载了凭据作为json文件。
现在在我的macbook上使用credentials.json时,gspread认证工作正常。当把相同的配置移动到linux服务器时,它给出了403不足的许可错误。
pip和python版本是相同的。
$ b
gspread.v4.exceptions.APIError:{
错误:{
errors:[
{
domain:global,
reason:insufficientPermissions,
message:权限不足
,
code:403,
message:权限不足
}
}
基本代码 $ b
从oauth2client.service_account导入gspread
import ServiceAccountCredentials $ b $ scope = ['https://spreadsheets.google.com/feeds']
creds = ServiceAccountCredentials.from_json_keyfile_name ('credentials.json',scope)
client = gspread.authorize(creds)
$ b sheet = client.open('MySheetName')。sheet1
范围
变量更改为以下内容: scope = ['https://spreadsheets.google.com/feeds',
'https://www.googleapis.com/auth/drive']
确保Drive API已在API控制台中启用。
gspread已升级,现在是基于API v4。它的速度更快,但它需要更新范围。
以下是相同的问题:
Using developers.google.com we created api user and downloaded credentials as json file. Now On my macbook gspread authentication is working fine while using credentials.json. when moved same config to linux server on aws its giving 403 insufficient permission error.
Pip and python version are same.
exception
gspread.v4.exceptions.APIError: { "error": { "errors": [ { "domain": "global", "reason": "insufficientPermissions", "message": "Insufficient Permission" } ], "code": 403, "message": "Insufficient Permission" } }
basic code
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
解决方案Try to change your
scope
variable to the following:scope = ['https://spreadsheets.google.com/feeds', 'https://www.googleapis.com/auth/drive']
Make sure Drive API is enabled in API console.
gspread has been upgraded and it's now based on API v4. It's faster but it requires updates in scope.
Here's the same issue: https://github.com/burnash/gspread/issues/512
这篇关于gspread认证投入不足的权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!