2

I have a gspread Python script which has been working perfectly for 6 months. Now suddenly I'm receiving an error when trying to authorize my service account credentials.

Here is the error:

raise HttpAccessTokenRefreshError(error_msg, status=resp.status)
    oauth2client.client.HttpAccessTokenRefreshError: internal_failure

Here is my auth code:

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

credentials = ServiceAccountCredentials.from_json_keyfile_name("assets/My Project-0101001.json", scope)
google_client = gspread.authorize(credentials)

I have tried creating new service accounts and even using an entirely different google account to generate a new refresh token, but nothing is working for me. This is fairly annoying as the script was working with no issues for months, now suddenly it decides to fail. Can anyone help?

R001W
  • 71
  • 3
  • I haven't seen the `internal_failure` before. Did you try to refresh credentials with `credentials.refresh()`? – Burnash Nov 21 '16 at 10:16
  • I have tried `credentials.refresh()` but I just get an error as I'm not passing in an http object. I am unsure how to do this. – R001W Nov 21 '16 at 18:27
  • Sorry, try to pass an http object `refresh()` expects. i.e. `credentials.refresh(httplib2.Http())`, don't forget to `import httplib2` before that. – Burnash Nov 21 '16 at 20:33
  • Thanks. I've just tried `credentials.refresh(httplib2.Http())` and I still get the same Traceback when I try to force a refresh of the access_token. I'm completely stumped as to why this would be happening. – R001W Nov 21 '16 at 21:14
  • I can only suggest starting from scratch in a new Python environment (or virtualenv). Make sure you have latest oauth2client installed. The only `internal_failure` info related to Google API I was able to find is here https://groups.google.com/forum/#!topic/adwords-api/f13W-C4ffL4 – Burnash Nov 22 '16 at 00:33
  • My error seems to have changed after trying from a different machine. `HTTPError: 401: Unauthorized

    Unauthorized

    Error 401

    `
    – R001W Nov 23 '16 at 00:36
  • At least it's not an internal failure anymore. Do you use the same `client_email`? – Burnash Nov 23 '16 at 12:52
  • I have tried multiple `client_emails` and deleting/recreating API projects whilst trying to troubleshoot this issue, but I still receive the 401 error. My script does now successfully run when using a different Google account on a different machine. When I run the script in a debugger I can see that now an `access_token` is being generated and authorized. This new error occurs when trying to call: `google_client.open("MyGSheet").sheet1` even though I have shared the new `client_email` with the sheet multiple times. – R001W Nov 23 '16 at 22:20
  • **Solved.** The second error was due to an dumb oversight on my part, (incorrect scope `https` twice in the list instead of `http, https`). For the record the `internal_error` was solved by deleting the Google API project entirely and creating a new project and service account from scratch. Thanks for the help! – R001W Nov 23 '16 at 22:58
  • Great news. I suggest you posting this as an answer to the question. Could be helpful to someone. – Burnash Nov 25 '16 at 15:57

1 Answers1

0

Solved by deleting my Google API Project in the Developer Console. Then creating a new project and service account from scratch.

R001W
  • 71
  • 3