获取google Oauth2 的access_token?

安装了Google api的python library, 运行后,报连接超时的错,是我的代理没有设置好么?但是我上google都没有问题?我用的是pycharm

from oauth2client.service_account import ServiceAccountCredentials
fsm_scope = 'https://www.googleapis.com/auth/firebase.messaging'


def _get_access_token():
  """Retrieve a valid access token that can be used to authorize requests.

  :return: Access token.
  """
  credentials = ServiceAccountCredentials.from_json_keyfile_name(
      'service-account.json', fsm_scope)
  access_token_info = credentials.get_access_token()
  return access_token_info.access_token

_get_access_token()

报错信息:
TimeoutError: [WinError 10060] 由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败。

阅读 6.2k
2 个回答

超时的话就是无法连接,就像你无法连接到谷歌一样,你试一下后缀改成cn可不可以,毕竟谷歌的一些服务已经可以在国内访问了,例如http://ditu.google.cn.

网络问题,我在测试服务器上跑python脚本就没有这个问题了

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题