0

gspread を使用できるように、Google 認証に oauth2client を使用しようとする Python プログラムがあります。これは私のコードです:

import sys, os, requests, gspread, ast
from oauth2client.client import SignedJwtAssertionCredentials

f = file(os.path.join('service_account_key.json'), 'rb')
SIGNED_KEY = f.read()
f.close()
scope = ['https://spreadsheets.google.com/feeds', 'https://docs.google.com/feeds']
credentials = SignedJwtAssertionCredentials('<my email address>', SIGNED_KEY, scope)

data = {
'refresh_token' : '<my refresh toked',
'client_id' : '<my client id>',
'client_secret' : '<my client secret>',
'grant_type' : 'refresh_token',
}

r = requests.post('https://accounts.google.com/o/oauth2/token', data = data)
credentials.access_token = ast.literal_eval(r.text)['access_token']
gc = gspread.authorize(credentials)

このコードは主にこのサイトから取得したもので、認証のセットアップに使用した手順も含まれています。コードはラップトップ (Windows) では機能しますが、Raspberry Pi (Linux) では次のエラーが発生します。

Traceback (most recent call last):
  File "save.py", line 19, in <module>
    r = requests.post('https://accounts.google.com/o/oauth2/token', data = data)
  File "/usr/local/lib/python2.7/dist-packages/requests/api.py", line 111, in post
    return request('post', url, data=data, json=json, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/requests/api.py", line 57, in request
    return session.request(method=method, url=url, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/requests/sessions.py", line 475, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/local/lib/python2.7/dist-packages/requests/sessions.py", line 585, in send
    r = adapter.send(request, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/requests/adapters.py", line 467, in send
    raise ConnectionError(e, request = request)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='accounts.google.com', port=443): Max retries exceeded with url: /o/oauth2/token (Caused by NewConnectionError('<requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0xf22290>: Failed to establish a new connection: [Errno -2] Name or service not known',))

誰が何が起こっているのか知っていますか?

4

0 に答える 0