HttpAccessTokenRefreshError,通过 python gspread 连接到 google sheet API 时出现此错误
HttpAccessTokenRefreshError, Getting this error while connecting to google sheet API through python gspread
我正在尝试连接到 google 通过 python 传播 sheet 并且在验证我的凭据时出现以下错误:
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.
我确保启用了以下所有内容。
- Google sheet 和 google Drive API 在我的控制台中启用。
- Google 云存储和 Google 云存储 json API 已启用
- 我正在尝试执行 gspread 操作的 google sheet 是
与 client_email_id 共享(在 json 文件中提到,在我之后下载
从 google 控制台创建了我的凭据)
- 我在代理后面,我正在使用 http_proxy 和 https_proxy 环境。变量
我的代码:
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())
我希望能够通过 python 连接到 google sheet 以便我能够在 [=54] 上执行读取、写入和更新操作=].我是 python 的新手。如果我在发布问题时犯了错误,请提前道歉
答案在问题中
invalid_scope:
http://www.googleapis.com/auth/drive is not a valid audience string.
应该是https://www.googleapis.com/auth/drive
我正在尝试连接到 google 通过 python 传播 sheet 并且在验证我的凭据时出现以下错误:
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.
我确保启用了以下所有内容。
- Google sheet 和 google Drive API 在我的控制台中启用。
- Google 云存储和 Google 云存储 json API 已启用
- 我正在尝试执行 gspread 操作的 google sheet 是 与 client_email_id 共享(在 json 文件中提到,在我之后下载 从 google 控制台创建了我的凭据)
- 我在代理后面,我正在使用 http_proxy 和 https_proxy 环境。变量
我的代码:
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())
我希望能够通过 python 连接到 google sheet 以便我能够在 [=54] 上执行读取、写入和更新操作=].我是 python 的新手。如果我在发布问题时犯了错误,请提前道歉
答案在问题中
invalid_scope:
http://www.googleapis.com/auth/drive is not a valid audience string.
应该是https://www.googleapis.com/auth/drive