How to fix the "google.auth.exceptions.RefreshError: ('No access token in response." when trying to open a spreadsheet using GoogleSheet API
Asked Answered
F

1

6

I followed the video from TechWithTim step by step (https://www.youtube.com/watch?v=cnPlKLEGR7E) but I am still getting an error when I try to open the sheet. The code works fine until sheet = client.open("GuildTaxes").sheet1 line. Here is my code.

import gspread
from oauth2client.service_account import ServiceAccountCredentials

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

creds = ServiceAccountCredentials.from_json_keyfile_name("GuildTaxes-9ba4508be840.json", scope)

client = gspread.authorize(creds)

sheet = client.open("GuildTaxes").sheet1

data = sheet.get_all_records()

print(data)
Finegrain answered 20/8, 2020 at 20:35 Comment(1)
In your case, when the Spreadsheet ID is used like sheet = client.open_by_key("###") instead of client.open("GuildTaxes"), what result will you retrieve?Berkly
F
18

I found the answer! After 2 hours, the scope in TechWithTim's video doesn't work for me, so if you stumble upon the same issue try using this one

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

It is the default scope.

Finegrain answered 21/8, 2020 at 7:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.