首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >尝试连接到扩展时的RefreshError

尝试连接到扩展时的RefreshError
EN

Stack Overflow用户
提问于 2022-09-30 12:08:09
回答 1查看 80关注 0票数 0

我花了一周时间好好工作,突然试图打开电子表格,我得到了以下错误:

代码语言:javascript
运行
复制
RefreshError: ('invalid_client: Unauthorized', {'error': 'invalid_client', 'error_description': 'Unauthorized'})

以下是简单的使用方法:

代码语言:javascript
运行
复制
gc = gspread.oauth(credentials_filename='credentials.json')
master="filename"
master_file_sh = gc.open(master)

使用google的方法,认证工作得很好,甚至多次尝试重置凭据,结果都没有成功。

知道为什么会失败吗?我知道信息清楚地说明了原因,但不可能是这样的。

任何建议都是欢迎的。

EN

回答 1

Stack Overflow用户

发布于 2022-10-04 15:32:38

我设法以不同的方式使用凭据来解决这个问题,而不是像下面这样重新分析后端:

代码语言:javascript
运行
复制
from google.oauth2.credentials import Credentials
from google_auth_oauthlib.flow import InstalledAppFlow

import os

creds = None

if os.path.exists('token.json'):
    creds = Credentials.from_authorized_user_file('token.json', scope)

if not creds or not creds.valid:
    if creds and creds.expired and creds.refresh_token:
        creds.refresh(Request())
    else:
        flow = InstalledAppFlow.from_client_secrets_file(
            'credentials.json', scope)
        creds = flow.run_local_server(port=0)
    # Save the credentials for the next run
    with open('token.json', 'w') as token:
        token.write(creds.to_json())

gc=gspread.authorize(creds)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73908533

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档