如何解决尝试从python访问电子表格时发生RefreshError 注意:
我尝试按照this教程从python访问电子表格GetHookedTest
。
我已成功添加服务帐户,这是我的凭据。与 test@gethooked.iam.gserviceaccount.com
{
"type": "service_account","project_id": "gethooked","private_key_id": "aaaaaabbbbbaaaabbbbaaaaa","private_key": "Private Key here","client_email": "test@gethooked.iam.gserviceaccount.com","client_id": "454454554","auth_uri": "https://accounts.google.com/o/oauth2/auth","token_uri": "https://oauth2.googleapis.com/token","auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs","client_x509_cert_url": "https://www.googleapis.com/robot/v1/Metadata/x509/orderplacer%test.iam.gserviceaccount.com"
}
import gspread
from oauth2client.service_account import ServiceAccountCredentials
import pprint
scope = ["https://spreadsheets.google.com/Feeds",'https://www.googleapis.com/auth/spreasheets',"https://www.googleapis.com/auth/drive.file","https://www.googleapis.com/auth/drive"]
creds = ServiceAccountCredentials.from_json_keyfile_name("client_secret.json",scope)
client = gspread.authorize(creds)
sheet = client.open("GetHookedTest").sheet1
但是我收到了 RefreshError
six.raise_from(new_exc,caught_exc)
File "<string>",line 3,in raise_from
google.auth.exceptions.RefreshError: ('No access token in response.',{'id_token': 'long string'})
解决方法
作为一种方法,请尝试以下修改。
-
删除
https://spreadsheets.google.com/feeds
和https://www.googleapis.com/auth/drive.file
的范围。 -
使用电子表格ID代替电子表格名称。
-
来自
client.open("GetHookedTest").sheet1
-
收件人
client.open_by_key("SpreadsheetId").sheet1
-
注意:
- 在your reply comment中,
https://www.googleapis.com/auth/spreasheets
是https://www.googleapis.com/auth/spreadsheets
。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。