0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

spreadsheet API KeyError: 'access_token'

Posted at

pythonでspreadsheetを操作するものを作成中にエラーが出た

遭遇したエラー

KeyError                                  Traceback (most recent call last)
~\anaconda3\lib\site-packages\google\oauth2\_client.py in jwt_grant(request, token_uri, assertion)
    195     try:
--> 196         access_token = response_data["access_token"]
    197     except KeyError as caught_exc:

KeyError: 'access_token'

<解決>
変更前

SCOPES = [
    'https://spreadsheets.com/feeds',
    'https://www.googleapis.com/auth/drive',
]
SERVICE_ACCOUNT_FILE = './hogehoge.json'
SHEET = 'hoge'

変更後
https://stackoverflow.com/questions/63418603/google-oauth2-no-access-token-in-response-error-while-trying-to-open-spreadshe
上記サイトを参考に
SCOPESにURLを追加した(コピペしただけ)

SCOPES = ["https://spreadsheets.google.com/feeds",
          'https://www.googleapis.com/auth/spreadsheets',
          "https://www.googleapis.com/auth/drive.file",
          "https://www.googleapis.com/auth/drive"]
SERVICE_ACCOUNT_FILE = './hogehoge.json'
SHEET = 'hoge'

これで解決しない場合にはjsonファイルのパスを確認してみてほしい
僕の場合jsonファイルがpyファイルと同じディレクトリにあるのでパスが'./hogehoge.json'となっている

下記の動画を参考にしていたところ、このエラーに遭遇した。

・PythonでGoogleスプレッドシートの作業を一瞬で終わらせる
https://youtu.be/fFSGPciIkfI
・PythonでGoogleスプレッドシートの情報を抽出してみた
https://youtu.be/uBy7F4Wd9cE

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?