Gspread访问谷歌电子表格:HttpAccessTokenRefreshError,JWT无效 [英] Gspread to access google spreadsheet: HttpAccessTokenRefreshError, invalid JWT

查看:216
本文介绍了Gspread访问谷歌电子表格:HttpAccessTokenRefreshError,JWT无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



以下是我到目前为止的内容:

 从oauth2client.service_account导入gspread 
import ServiceAccountCredentials



scope = ['https: //breadsheets.google.com/feeds']

凭证= ServiceAccountCredentials.from_json_keyfile_name(
'credentials.json',范围)

gc = gspread.authorize (凭证)

wks = gc.open(PracticeOpsBS)。sheet1

结果是一堆东西,我想是告诉我发生了什么事情,导致以下结果:

  HttpAccessTokenRefreshError:invalid_grant:无效的JWT签名。 

最终,我希望能够从这张工作表的两个标签中获取信息来做一些分析,但还没有能够从谷歌拉到python的数据。任何帮助表示赞赏,我会尽我所能回答任何澄清问题! 解决方案

看起来这是版本问题我正在使用的oauth2client。为了解决问题,我将其降级到了oauth2client版本1.5.1。然后,我使用以下方式访问电子表格:

  import json 
从oauth2client导入gspread
.client import SignedJwtAssertionCredentials

json_key = json.load(open('credentials.json'))
scope = ['https://spreadsheets.google.com/feeds']

credentials = SignedJwtAssertionCredentials(
json_key ['client_email'],json_key ['private_key'],作用域)


gc = gspread.authorize(credentials)

wks = gc.open('PracticeOpsBS')


I'm struggling to get access to a google spreadsheet with python 2.7 using gspread.

Here's what I have so far:

import gspread
from oauth2client.service_account import ServiceAccountCredentials



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

credentials = ServiceAccountCredentials.from_json_keyfile_name(
    'credentials.json', scope)

gc = gspread.authorize(credentials)

wks = gc.open("PracticeOpsBS").sheet1

The result is a bunch of stuff that I think is showing me what is going on, resulting in the following:

"HttpAccessTokenRefreshError: invalid_grant: Invalid JWT Signature."

Ultimately I'm hoping to access the information from two tabs of this worksheet to do some analysis, but haven't been able to pull the data in to python from google. Any help is appreciated and I'll answer any clarifying questions as I can!

解决方案

Looks like it was an issue with the version of oauth2client that I was using. To get things to work, I downgraded to oauth2client version 1.5.1. Then I used the following to gain access to the spreadsheet:

import json
import gspread
from oauth2client.client import SignedJwtAssertionCredentials

json_key = json.load(open('credentials.json'))
scope = ['https://spreadsheets.google.com/feeds']

credentials = SignedJwtAssertionCredentials(
    json_key['client_email'], json_key['private_key'], scope)


gc = gspread.authorize(credentials)

wks = gc.open('PracticeOpsBS')

这篇关于Gspread访问谷歌电子表格:HttpAccessTokenRefreshError,JWT无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆