sam
sam

Reputation: 69

HttpAccessTokenRefreshError, Getting this error while connecting to google sheet API through python gspread

I am trying to connect to google spread sheets through python and while getting my credentials validated i get the following error :

Error:
   Traceback (most recent call last):
   File 
   "C:\Users\skansal\Desktop\Agile_Tool\Agile_Google_Sheets\Google_Api.py", 
   line 10, in 
   gs = gspread.authorize(credentials)
   File "C:\Users\skansal\AppData\Local\Programs\Python\Python36\lib\site- 
   packages\gspread_init_.py", line 38, in authorize
   client.login()
   File "C:\Users\skansal\AppData\Local\Programs\Python\Python36\lib\site- 
   packages\gspread\client.py", line 51, in login
   self.auth.refresh(http)
   File "C:\Users\skansal\AppData\Local\Programs\Python\Python36\lib\site- 
   packages\oauth2client\client.py", line 545, in refresh
   self._refresh(http)
   File "C:\Users\skansal\AppData\Local\Programs\Python\Python36\lib\site- 
   packages\oauth2client\client.py", line 749, in _refresh
   self._do_refresh_request(http)
   File "C:\Users\skansal\AppData\Local\Programs\Python\Python36\lib\site- 
   packages\oauth2client\client.py", line 819, in _do_refresh_request
   raise HttpAccessTokenRefreshError(error_msg, status=resp.status)
   oauth2client.client.HttpAccessTokenRefreshError: invalid_scope: 
   http://www.googleapis.com/auth/drive is not a valid audience string.

I made sure all the following things are enabled.

My Code:

from oauth2client.service_account import ServiceAccountCredentials
import httplib2
import gspread
scope = ['http://www.googleapis.com/auth/drive']
credentials = ServiceAccountCredentials.from_json_keyfile_name('credential_token.json',scope)

gs = gspread.authorize(credentials)
worksheet = gc.open('Project_Sheet').sheet1
print(wks.get_all_records())

I want to be able to connect to the google sheet through python so that i would be able to perform the read,write and update operations on the sheet. I am new to python. Sorry in advance if i made a mistake while posting the question

Upvotes: 0

Views: 427

Answers (1)

pinoyyid
pinoyyid

Reputation: 22306

The answer is in the question

invalid_scope: http://www.googleapis.com/auth/drive is not a valid audience string.

It should be https://www.googleapis.com/auth/drive

Upvotes: 2

Related Questions