我有一个python脚本使用oauth2client
和gspread
通过Raspberry pi成功更新Google工作表。当我尝试从我的桌面Ubuntu运行相同的脚本时,它会抛出错误403 Insufficient Permissions
。如果重要的话,我会在IDLE2
中运行它们。
我是新手,但我导入了gspread
& oauth2client
个库,以及一些名为pypy
,openSSL
& pycrypto
。我已经从Raspberry pi复制了整个文件夹,并从该文件夹中运行它,因此它包含相同的json
密钥文档。
我可能遗漏了一些明显的东西。如果你能回答,请为相关的新手愚蠢。谢谢。
更新3月13日晚9点20分:我从谷歌直接下载了新的凭据到Ubuntu,更新了代码并再次尝试但收到了同样的错误。
这是错误:
`Traceback (most recent call last):
File "/home/heather/Desktop/Heather/DEV/18-03-11-Category-Log.py", line 15, in <module>
wks = gc.open("meditation_logger").sheet1
File "/home/heather/.local/lib/python2.7/site-packages/gspread/v4/client.py", line 103, in open
self.list_spreadsheet_files()
File "/home/heather/.local/lib/python2.7/site-packages/gspread/v4/client.py", line 80, in list_spreadsheet_files
r = self.request('get', url)
File "/home/heather/.local/lib/python2.7/site-packages/gspread/v4/client.py", line 73, in request
raise APIError(response)
APIError: {
"error": {
"errors": [
{
"domain": "global",
"reason": "insufficientPermissions",
"message": "Insufficient Permission"
}
],
"code": 403,
"message": "Insufficient Permission"
}
}`
以下是代码(我使用####来覆盖我的密钥文件名):
import gspread
from oauth2client.service_account import ServiceAccountCredentials
from datetime import datetime
import serial
from time import localtime, strftime
#import time
import serial
#rpi serial port with arduino
ser = serial.Serial('/dev/ttyACM0',115200)
scope = ['https://spreadsheets.google.com/feeds']
credentials = ServiceAccountCredentials.from_json_keyfile_name('################.json', scope)
gc = gspread.authorize(credentials)
#sh = gc.create('meditation_logger1')
wks = gc.open("meditation_logger").sheet1
wks.resize(1)
#wks.update_acell('B2', 'crud')
def ok_to_begin():
print "ok to begin"
ok_to_begin()
while True:
wks = gc.open("meditation_logger").sheet1
data = ser.readline().strip()
(...等我认为其余的代码并不真正相关......只记录不同串行数据的指令)