Here are some notes on how to access Google Spreadsheets using python on raspberry pi.
・ ↓ Preparation to write / read on google spread sheet https://qiita.com/akabei/items/0eac37cb852ad476c6b9
Code to prepare with raspberry pi
Called side
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 sample').sheet1
wks.update_acell('A1', 'Hello World!')
print(wks.acell('A1'))
if __name__ == "__main__":
main()
Caller
yobu.py
import test
test.main()
The following problems appeared in different LAN environments (home LAN and laboratory 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.
This was a problem caused by the internal time of the OS not being synchronized with the current time.
sudo date --set='2020/01/07 16:54'
It was solved by manually adjusting the time like this.
I got this error
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 /
Recommended Posts