I am new to python and have been working with gspread for a couple months now and keep getting it working then it comes up with an error the next day!
I have an RFID module sending data to google sheets. Sometimes Google API accepts the data, sometimes it doesn't and I really can't figure out the solution after searching for a few days now (tearing my hair out).
I am using Raspberry Pi 3, python 2.7 and gspread to send to google drive API where the info is logged in google docs. I have reset the ntp servers to local ones so the time is correct and I've even set a cron reboot to happen during the day to see if it will refresh any error that pops up. I have the .py file and .json on the pi's desktop.
This is my error: "HttpAccessTokenRefreshError: invalid_grant: Invalid JWT Signature."
Code is below. Thanks for any help or suggestions :)
import serial
import re
import time
import gspread
import json
from oauth2client.service_account import ServiceAccountCredentials
pattern = r"(\d+\.\d*)_(\d+\.\d*)\r\n"enter code here
#port = '/dev/ttyACM1'
port2 = "/dev/ttyACM0"
scope = ['https://spreadsheets.google.com/feeds']
credentials = ServiceAccountCredentials.from_json_keyfile_name('My Project-xxxxxxxxxxxx.json', scope)
ser = serial.Serial(port2, 115200, timeout = 1)
if ser.isOpen():
print "connected"
while True:
line = ser.readline()
if len(line) > 2:
m = re.match(pattern, line)
tableline = [str(time.strftime("%d/%m/%Y")), str(time.strftime("%H:%M:%S")), line]# previously m.group(1), m.group(2)
gc = gspread.authorize(credentials)
wks = gc.open("example").sheet1
wks.append_row(tableline)
print (tableline)
time.sleep(30)
else:
time.sleep(1)
else:
print ("Failure opening serial port at " + port)