简体   繁体   English

Gspread访问谷歌电子表格:HttpAccessTokenRefreshError,无效的JWT

[英]Gspread to access google spreadsheet: HttpAccessTokenRefreshError, invalid JWT

I'm struggling to get access to a google spreadsheet with python 2.7 using gspread. 我正在努力使用gspread访问使用python 2.7的谷歌电子表格。

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. 最终我希望从这个工作表的两个选项卡中访问信息来进行一些分析,但是无法从google将数据提取到python中。 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. 看起来这是我使用的oauth2client版本的问题。 To get things to work, I downgraded to oauth2client version 1.5.1. 为了让事情发挥作用,我降级为oauth2client版本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')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM