gspread authentication throwing insufficient permission
Asked Answered
O

3

14

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
Offshore answered 13/3, 2018 at 14:18 Comment(2)
I am seeing a similar problem on one of my two linux servers. The only difference I can currently between my servers is what version of gspread they have installed, maybe check what version of gspread your two machines are using? Please let me know how you resolve!Regionalism
I rolled back the version of gspread on my linux server which was experiencing the same issue and this seems to have fixed the issue for me, implying gspread 2.0 might be to blame, hope yours is a similar issue. This is what I ran: pip install 'gspread==0.6.2' --force-reinstallRegionalism
M
42

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

Mongoose answered 15/3, 2018 at 9:6 Comment(1)
worked for me! at first it gave me 'permission denied' and a link to activate first execution. after that it worked.Daria
B
2

You appear to be using a service account. In order for the service account to access your sperad sheet it needs to have access to it.

Make sure that you share the sheet with the service account email address you can do that though google drive web page

Boaz answered 13/3, 2018 at 15:29 Comment(1)
I don't think this can this be the issue, OP says the service account works on a Macbook but not on the linux server, so it must have access.Regionalism
A
0

IF you are unable to access even after updating the scope, try running this command in your terminal:

sudo pip install 'gspread==0.6.2' --force-reinstall

Alto answered 5/5, 2018 at 13:8 Comment(1)
I would discourage people from downgrading: gspread 0.6.2 uses the older version of Sheets API (v3). Google strongly recommends upgrading from v3 as it will be deprecated. See developers.google.com/sheets/api/v3Mongoose

© 2022 - 2024 — McMap. All rights reserved.