python gspread oauth2client.client.HttpAccessTokenRefreshError : invalid_grant 错误

标签 python oauth-2.0 gspread

根据以下帖子#244要验证凭据,我们可以定义 GOOGLE_APPLICATION_CREDENTIALS 环境变量来直接进行身份验证。

这是我在代码中所做的。

import gspread
from oauth2client.client import GoogleCredentials
credentials = GoogleCredentials.get_application_default()
credentials.create_scoped(['https://spreadsheets.google.com/feeds'])
gc = gspread.authorize(credentials)
wks = gc.open("hello").sheet1

但是当我运行它时它会引发 oauth2client.client.HttpAccessTokenRefreshError: invalid_grant

关于如何解决这个问题有什么建议吗?

谢谢,

最佳答案

这可能是服务器时间的问题(运行“date”命令)。我建议在您的服务器上设置 NTP 以使其自动更新时间。

CentOS NTP http://www.cyberciti.biz/faq/howto-install-ntp-to-synchronize-server-clock/

Ubuntu NTP https://www.digitalocean.com/community/tutorials/how-to-set-up-time-synchronization-on-ubuntu-12-04

关于python gspread oauth2client.client.HttpAccessTokenRefreshError : invalid_grant 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34867516/

相关文章:

python - 取消选中单选按钮 - PyQt4

ruby-on-rails - rails/设计 : undefined method `router_name' for nil:NilClass - what is coming through as nil?

python gspread 谷歌电子表格保持连接

oauth-2.0 - 尝试连接到 Google Oauth for google API 时 JWT 无效

python - 按行而不是单元格填充谷歌电子表格

excel - 如何从谷歌表格单元格中读取评论?

python - numpy.memmap 到 Image.frombuffer - 不复制

python - 如何更改嵌套字典中的值

python - 使用 Kivy/Buildozer 后,我在 Android 上打开应用程序时遇到问题

c# - 使用 Azure Active Directory 进行 Azure Function 身份验证