1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

raspberry piでpythonを用いてグーグルスプレッドシートにアクセスする(自分用)

Last updated at Posted at 2020-01-07

目的

raspberry piでpythonを用いてグーグルスプレッドシートにアクセスするまでの覚え書きを記します

準備

・↓google spread sheet に書き込み・読み取りをする準備まで
https://qiita.com/akabei/items/0eac37cb852ad476c6b9

raspberry piで準備するコード

呼ばれる側

test.py
import sys
sys.path.append('/usr/lib/python3/dist-packages')
import gspread
from oauth2client.service_account import ServiceAccountCredentials

def main():
        scope = ['https://spreadsheets.google.com/feeds','https://www.googleapis.com/auth/drive']
        credentials = ServiceAccountCredentials.from_json_keyfile_name('/home/pi/Downloads/xxxxxxxxxxx.json', scope)
        gc = gspread.authorize(credentials)
        wks = gc.open('gspreadサンプル').sheet1
        wks.update_acell('A1', 'Hello World!')
        print(wks.acell('A1'))

if __name__ == "__main__":
        main()

呼ぶ側

yobu.py

import test
test.main()

問題

LANの異なる環境(自宅のLANと研究室のLAN)で以下のような問題が現れた.

raise HttpAccessTokenRefreshError(error_msg, status=resp.status)
oauth2client.client.HttpAccessTokenRefreshError: invalid_grant: Invalid JWT: Token must be a short-lived token (60 minutes) and in a reasonable timeframe. Check your iat and exp values and use a clock with skew to account for clock differences between systems.

これはOSの内部時刻が現在時刻と同期されてないことに起因する問題だった.

sudo date --set='2020/01/07 16:54'

このように手動で時刻を合わせることで解決した

追記

こんなエラーがでた

Requirement already satisfied: requests in /usr/lib/python3/dist-packages (2.21.0)
Could not fetch URL https://www.piwheels.org/simple/pip/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='www.piwheels.org', port=443): Max retries exceeded with url: /simple/pip/ (Caused by SSLError(SSLError("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')])"))) - skipping

参考文献

https://qiita.com/AAkira/items/22719cbbd41b26dbd0d1
https://hombre-nuevo.com/microcomputer/raspberrypi/raspberrypi0044/
https://www.xn--tckk6a9dufrb.com/raspberry-piraspbian%E3%81%AEntp%E3%82%B5%E3%83%BC%E3%83%90%E8%A8%AD%E5%AE%9A/

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?