question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

gspread.v4.exceptions.APIError - UNAUTHENTICATED

See original GitHub issue

Python version: 3.6 gspread version: 2.0.0

Honestly I don’t know what happened. One day it was working and the next day (today) authentication is failing.

Code

scope = ['https://spreadsheets.google.com/feeds',
         'https://www.googleapis.com/auth/drive']
creds = ServiceAccountCredentials.from_json_keyfile_name(
    "client-secret.json",
    scope
)
client = gspread.authorize(creds)
spreadsheet_key = "28934823459U24IR904RUI0924UR02834UR"
sheet = client.open_by_key(spreadsheet_key).worksheet("Log")

Error

2018-04-03T09:40:08.062563+00:00 app[web.1]: gspread.v4.exceptions.APIError: {

2018-04-03T09:40:08.062565+00:00 app[web.1]:   "error": {

2018-04-03T09:40:08.062566+00:00 app[web.1]:     "code": 401,

2018-04-03T09:40:08.062572+00:00 app[web.1]:     "message": "Request had invalid authentication      credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.",

2018-04-03T09:40:08.062573+00:00 app[web.1]:     "status": "UNAUTHENTICATED"

2018-04-03T09:40:08.062574+00:00 app[web.1]:   }

2018-04-03T09:40:08.062576+00:00 app[web.1]: }

I checked issue #512 but I already had the right scope from the very start.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8

github_iconTop GitHub Comments

3reactions
raivatshahcommented, Aug 20, 2019

Why was this issue closed without a solution?

0reactions
guztakacommented, Oct 13, 2018

Hi, I think this will help you. https://stackoverflow.com/questions/45914349/python-gspread-request-error-401

The access_token have a lifetime so you have to do a simple gc.login()

Read more comments on GitHub >

github_iconTop Results From Across the Web

Developers - gspread.v4.exceptions.APIError - UNAUTHENTICATED -
Python version: 3.6 gspread version: 2.0.0. Honestly I don't know what happened. One day it was working and the next day (today) authentication...
Read more >
python3 gspread exception not caught - Stack Overflow
exceptions.APIError as UNAUTHENTICATED: print("Api error occurred for gspread due to authentication failure while writing What ever value.").
Read more >
Exceptions — gspread 5.7.0 documentation
Trying to open non-existent or inaccessible spreadsheet. exception gspread.exceptions.UnSupportedExportFormat¶. Raised when export format is ...
Read more >
[Example code]-python3 gspread exception not caught
I have the following piece of code which attempts to capture a gspread.exceptions.APIError, usually as the result of a timeout of the Google...
Read more >
"Exceeds grid limits" error when batch updating a Spreadsheet
Either email addresses are anonymous for this group or you need the view member ... Nov 22, 2016, 4:45:33 AM11/22/16 ... Dec 30,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found