调用GoogleSheetsAPI问题的Python discord bot
我现在在我的discord机器人上随机遇到了一个奇怪的错误。它使用python,只调用GoogleSheetsAPI并打印在一系列单元格中找到的信息。我目前在另一个房间的raspberry pi上运行它,它在那里工作正常,但我无法在任何地方创建另一个机器人实例,因此我担心重新启动raspberry pi(以防它无法重新登录)。我曾经能够运行多个bot实例,所以这让我有点困惑 以下是授权代码:调用GoogleSheetsAPI问题的Python discord bot,python,api,google-sheets,Python,Api,Google Sheets,我现在在我的discord机器人上随机遇到了一个奇怪的错误。它使用python,只调用GoogleSheetsAPI并打印在一系列单元格中找到的信息。我目前在另一个房间的raspberry pi上运行它,它在那里工作正常,但我无法在任何地方创建另一个机器人实例,因此我担心重新启动raspberry pi(以防它无法重新登录)。我曾经能够运行多个bot实例,所以这让我有点困惑 以下是授权代码: import pickle import os.path from googleapiclien
import pickle
import os.path
from googleapiclient.discovery import build
from google_auth_oauthlib.flow import InstalledAppFlow
from google.auth.transport.requests import Request
from discord import Game
SCOPES = ['https://www.googleapis.com/auth/spreadsheets.readonly']
SAMPLE_SPREADSHEET_ID = 'my spreadsheet'
SAMPLE_RANGE_NAME = 'league!A2:R'
TOKEN = 'Token generated a while back'
client = discord.Client()
channel = client.get_channel('my channel')
@client.event
async def on_message(message):
if os.path.exists('token.pickle'):
with open('token.pickle', 'rb') as token:
creds = pickle.load(token)
if not creds or not creds.valid:
if creds and creds.expired and creds.refresh_token:
creds.refresh(Request())
else:
flow = InstalledAppFlow.from_client_secrets_file(
'credentials.json', SCOPES)
creds = flow.run_local_server(port=0)
with open('token.pickle', 'wb') as token:
pickle.dump(creds, token)
我花了一些时间研究可能出现的问题,它说Google sheets身份验证令牌可能有问题,但这些建议的修复似乎都不起作用。我非常感谢您的帮助,因为我对python非常陌生。pip和googleAPI文件一定是以某种方式损坏的,因为完全破坏和重置我的工作区似乎已经修复了它。您是否尝试过使用API资源管理器来验证在发出请求时是否有正确的参数?还有,代码在哪一行失败?我确实查看了API文档并完全重置了我的工作区(卸载了python并重新安装了所有必需的文件),它现在可以工作了。我想其中一个文件被破坏了。谢谢你的回复。