1

オンラインでGoogleシートを読み取る小さなpythonボットを実行し、ユーザーからプロンプトが表示されたときにその情報を不和にサーバーに送信しますが、1〜2か月間使用されておらず、現在は機能していません。そのため、Google認証サービスへの呼び出しでエラーをスローして認証資格情報を更新しているようで、何を試すべきかについてのアイデアがありません。完全なエラーと、それが壊れている完全なコード セクションを含めました。

Ignoring exception in on_message
Traceback (most recent call last):
  File "/home/pi/.local/lib/python3.7/site-packages/discord/client.py", line 312, in _run_event
    await coro(*args, **kwargs)
  File "/home/pi/Downloads/discordbot.py", line 32, in on_message
    creds.refresh(Request())
  File "/home/pi/.local/lib/python3.7/site-packages/google/oauth2/credentials.py", line 136, in refresh
    self._client_secret))
  File "/home/pi/.local/lib/python3.7/site-packages/google/oauth2/_client.py", line 237, in refresh_grant
    response_data = _token_endpoint_request(request, token_uri, body)
  File "/home/pi/.local/lib/python3.7/site-packages/google/oauth2/_client.py", line 111, in _token_endpoint_request
    _handle_error_response(response_body)
  File "/home/pi/.local/lib/python3.7/site-packages/google/oauth2/_client.py", line 61, in _handle_error_response
    error_details, response_body)
google.auth.exceptions.RefreshError: ('invalid_grant: Bad Request', '{\n  "error": "invalid_grant",\n  "error_description": "Bad Request"\n}')
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
# If modifying these scopes, delete the file token.pickle.
SCOPES = ['https://www.googleapis.com/auth/spreadsheets.readonly']
# The ID and range of a sample spreadsheet.
SAMPLE_SPREADSHEET_ID = '(replaced with generic text)'
SAMPLE_RANGE_NAME = 'league!A2:R'

TOKEN = '(replaced with generic text)'

client = discord.Client()
channel = client.get_channel(635962311693172776)
@client.event
async def on_message(message):
    # The file token.pickle stores the user's access and refresh tokens, and is
    # created automatically when the authorization flow completes for the first
    # time.
    if os.path.exists('token.pickle'):
        with open('token.pickle', 'rb') as token:
            creds = pickle.load(token)
    # If there are no (valid) credentials available, let the user log in.
    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)
        # Save the credentials for the next run
        with open('token.pickle', 'wb') as token:
            pickle.dump(creds, token)

    service = build('sheets', 'v4', credentials=creds)

    # Call the Sheets API
    sheet = service.spreadsheets()
    result = sheet.values().get(spreadsheetId=SAMPLE_SPREADSHEET_ID,
                                range=SAMPLE_RANGE_NAME).execute()

読んでくれてありがとう

4

0 に答える 0