Access google spreadsheet using python on raspberry pi (for myself)

Purpose

Here are some notes on how to access Google Spreadsheets using python on raspberry pi.

Preparation

・ ↓ 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()

problem

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.

Postscript

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

References

・ 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

Access google spreadsheet using python on raspberry pi (for myself)
Detect "brightness" using python on Raspberry Pi 3!
Run servomotor on Raspberry Pi 3 using python
Detect temperature using python on Raspberry Pi 3!
Detect slide switches using python on Raspberry Pi 3!
Detect magnet switches using python on Raspberry Pi 3!
Sound the buzzer using python on Raspberry Pi 3!
Output to "7-segment LED" using python on Raspberry Pi 3!
Run AWS IoT Device SDK for Python on Raspberry Pi
Cross-compiling for Raspberry Pi Zero on Debian-Try using shared libraries
Detect "temperature (using A / D converter)" using python on Raspberry Pi 3!
Raspberry pi initial setting (for myself)
Try using ArUco on Raspberry Pi
Install PyCall on Raspberry PI and try using GPIO's library for Python from Ruby
Control the motor with a motor driver using python on Raspberry Pi 3!
Notes for using OpenCV on Windows10 Python 3.8.3.
Adafruit Python BluefruitLE works on Raspberry Pi.
Creating Google Spreadsheet using Python / Google Data API
Working with GPS on Raspberry Pi 3 Python
python [for myself]
Detect analog signals with A / D converter using python on Raspberry Pi 3!
Initial settings for using GrovePi + starter kit and camera on Raspberry Pi
Try using a QR code on a Raspberry Pi
Tweet (API 1.1) on Google App Engine for Python
Make DHT11 available on Raspberry Pi + python (memo)
Beginning cross-compilation for Raspberry Pi Zero on Ubuntu
Connect to MySQL with Python on Raspberry Pi
Build a Python development environment on Raspberry Pi
[Raspberry Pi] Publish a web application on https using Apache + WSGI + Python Flask
Periodically notify the processing status of Raspberry Pi with python → Google Spreadsheet → LINE
Using the 1-Wire Digital Temperature Sensor DS18B20 from Python on a Raspberry Pi
pigpio on Raspberry pi
Cython on Raspberry Pi
Initial settings for using Python3.8 and pip on CentOS8
Build an OpenCV4 environment on Raspberry Pi using Poetry
[Heroku] Memo for deploying Python apps using Heroku on Windows [Python]
Try using the temperature sensor (LM75B) on the Raspberry Pi.
PIL with Python on Windows 8 (for Google App Engine)
Ubuntu 20.04 on raspberry pi 4 with OpenCV and use with python
Install pyenv on Raspberry Pi and version control Python
I tried to access Google Spread Sheets using Python
Use kintone API SDK for Python on Raspberry Pi (easily store data in kintone from Raspberry Pi)
Indoor monitoring using Raspberry Pi
VScode intellisense doesn't work on Raspberry Pi OS 64bit! (Python)
Python memo (for myself): Array
Update Python for Raspberry Pi to 3.7 or later with pyenv
Build an environment for machine learning using Python on MacOSX
Python Tkinter notes (for myself)
I made a resource monitor for Raspberry Pi with a spreadsheet
Raspberry Pi + Python + OpenGL memo
raspberry pi 1 model b, python
Access Google Drive with Python
Broadcast on LINE using python
Introduced pyenv on Raspberry Pi
Construction of Cortex-M development environment for TOPPERS using Raspberry Pi
Use NeoPixel on Raspberry Pi
Install OpenCV4 on Raspberry Pi 3
Install TensorFlow 1.15.0 on Raspberry Pi
Translate I2C device driver for Arduino to Python for Raspberry pi
Resolved an error when putting pygame in python3 on raspberry pi
Stream speech recognition using Google Cloud Speech gRPC API on python3 on Mac!