Ahsan Naseem
Ahsan Naseem

Reputation: 1106

gspread authentication throwing insufficient permission

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

Upvotes: 15

Views: 14822

Answers (3)

Yogamurthy
Yogamurthy

Reputation: 998

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

Upvotes: 0

Burnash
Burnash

Reputation: 3321

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

Upvotes: 43

Linda Lawton - DaImTo
Linda Lawton - DaImTo

Reputation: 117281

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

Upvotes: 2

Related Questions