'Errors with gspread with Python
I'm trying to use gspread API with ticketmaster API
This's the code for the json file should I refer to json Credentials file of Google APIs as I did or the file of the json data itself?
import gspread
from oauth2client.service_account import ServiceAccountCredentials
from pprint import pprint
scope = ["https://spreadsheets.google.com/feeds",'https://www.googleapis.com/auth/spreadsheets',"https://www.googleapis.com/auth/drive.file","https://www.googleapis.com/auth/drive"]
creds = ServiceAccountCredentials.from_json_keyfile_name("ticketmaster-350616-ae26457d3166.json", scope)
client = gspread.authorize(creds)
sheet = client.open("tutorial").sheet1 # Open the spreadhseet
data = sheet.get_all_records() # Get a list of all records
This's the json file that contains the data that I mean e.g.
{ "type": "service_account",
"project_id": "speeqedy-octane-317516",
"private_key_id": "yyyyyyyyy",
"private_key": "-----BEGIN PRIVATE KEY-----\xxxxxxxxx\n-----END PRIVATE KEY-----\n",
"client_email": "[email protected]",
"client_id": "102481923285078876543",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/cybor%40speedy-octane-317516.iam.gserviceaccount.com"
}
These are the Errors I get
Traceback (most recent call last):
File "C:\Python310\lib\site-packages\gspread\client.py", line 128, in open
properties = finditem(
File "C:\Python310\lib\site-packages\gspread\utils.py", line 88, in finditem
return next(item for item in seq if func(item))
StopIteration
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "c:\xampp\htdocs\Ticket\ticketmaster.py", line 29, in <module>
sheet = client.open("tutorial").sheet1 # Open the spreadhseet
File "C:\Python310\lib\site-packages\gspread\client.py", line 138, in open
raise SpreadsheetNotFound
gspread.exceptions.SpreadsheetNotFound
Solution 1:[1]
the problem is when you try to open the spreadsheet here: sheet = client.open("tutorial").sheet1.
As the error message says:
...
raise SpreadsheetNotFound
gspread.exceptions.SpreadsheetNotFound
Gspread cannot find this spreadsheet.
As mentioned in the documentation in open method documentation and in the authentication documentation ( bullet point 6, just below the service account file where it says "very important"):
- you must share your spreadsheet with this email (the email from the service account)
- if the spreadsheet does not exists it will raise the
SpreadshertNotFoundexception
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Lavigne958 |
