M. Freberg
M. Freberg

Reputation: 39

Google Sheets with Python Insufficient Permission

I am trying to use python and google sheets together. This is my code:

import gspread
from oauth2client.service_account import ServiceAccountCredentials

#use creds to create a client to interact with the Google Drive API
scope = ['https://spreadsheets.google.com/feeds']
creds = ServiceAccountCredentials.from_json_keyfile_name('client_secret.json', scope)
client = gspread.authorize(creds)

#Find a workbook by name and open the first sheet
#Make sure you use the right name here.
sheet = client.open("Year 9 Camp").sheet1

#Extract and print all of the values
list_of_hashes = sheet.get_all_records()
print(list_of_hashes)

However, it keeps coming up with an error:

Traceback (most recent call last):
  File "C:\Users\cswel\OneDrive\Documents\School\13CSC\spreedsheet.py.py", line 12, in <module>
    sheet = client.open("Year 9 Camp").sheet1
  File "C:\Python34\lib\site-packages\gspread\v4\client.py", line 103, in open
    self.list_spreadsheet_files()
  File "C:\Python34\lib\site-packages\gspread\v4\client.py", line 80, in list_spreadsheet_files
    r = self.request('get', url)
  File "C:\Python34\lib\site-packages\gspread\v4\client.py", line 73, in request
    raise APIError(response)
gspread.v4.exceptions.APIError: {
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "insufficientPermissions",
    "message": "Insufficient Permission"
   }
  ],
  "code": 403,
  "message": "Insufficient Permission"
 }
}

Can someone please help my error or give me a very easy way to connect google sheets and python? I am finding the tutorials on YouTube and online to be difficult to understand.

Much appreciated for any answers given.

Upvotes: 1

Views: 3567

Answers (1)

Abdul Qayyum
Abdul Qayyum

Reputation: 21

scope = ['https://spreadsheets.google.com/feeds']

just add the drive to the scope like below and it will work worked for me

scope = ['https://spreadsheets.google.com/feeds', 'https://www.googleapis.com/auth/drive']

Upvotes: 1

Related Questions