鍍金池/ 問答/Java  Python  網(wǎng)絡安全/ 獲取google Oauth2 的access_token?

獲取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] 由于連接方在一段時間后沒有正確答復或連接的主機沒有反應,連接嘗試失敗。

回答
編輯回答
鹿惑

網(wǎng)絡問題,我在測試服務器上跑python腳本就沒有這個問題了

2018年6月2日 18:50
編輯回答
離夢

超時的話就是無法連接,就像你無法連接到谷歌一樣,你試一下后綴改成cn可不可以,畢竟谷歌的一些服務已經(jīng)可以在國內(nèi)訪問了,例如http://ditu.google.cn.

2017年4月24日 23:30