Skip to content

Bad Request error when credential expires, requires manually deleting cached token.json file #13

@ForrestTrepte

Description

@ForrestTrepte

I was using gtasks-md with a personal Google account with oauth in testing mode as an external user. I believe tokens expire after 7 days.

At that point, I received the following error:

PS C:\Users\forre> gtasks-md view
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "c:\users\forre\.local\bin\gtasks-md.exe\__main__.py", line 7, in <module>
  File "C:\Users\forre\pipx\venvs\gtasks-md\Lib\site-packages\app\__main__.py", line 62, in main
    view(service)
  File "C:\Users\forre\pipx\venvs\gtasks-md\Lib\site-packages\app\__main__.py", line 141, in view
    _, text = fetch_task_lists(service)
              ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\forre\pipx\venvs\gtasks-md\Lib\site-packages\app\__main__.py", line 173, in fetch_task_lists
    task_lists = service.fetch_task_lists()
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\forre\pipx\venvs\gtasks-md\Lib\site-packages\app\googleapi.py", line 318, in fetch_task_lists
    task_lists = self.task_lists().list(maxResults=100).execute().get("items", [])
                 ^^^^^^^^^^^^^^^^^
  File "C:\Users\forre\pipx\venvs\gtasks-md\Lib\site-packages\app\googleapi.py", line 52, in task_lists
    return self._get_service().tasklists()
           ^^^^^^^^^^^^^^^^^^^
  File "C:\Users\forre\pipx\venvs\gtasks-md\Lib\site-packages\app\googleapi.py", line 389, in _get_service
    credentials=self.get_credentials(),
                ^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\forre\pipx\venvs\gtasks-md\Lib\site-packages\app\googleapi.py", line 365, in get_credentials
    creds.refresh(Request())
  File "C:\Users\forre\pipx\venvs\gtasks-md\Lib\site-packages\google\oauth2\credentials.py", line 409, in refresh
    ) = reauth.refresh_grant(
        ^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\forre\pipx\venvs\gtasks-md\Lib\site-packages\google\oauth2\reauth.py", line 366, in refresh_grant
    _client._handle_error_response(response_data, retryable_error)
  File "C:\Users\forre\pipx\venvs\gtasks-md\Lib\site-packages\google\oauth2\_client.py", line 69, in _handle_error_response
    raise exceptions.RefreshError(
google.auth.exceptions.RefreshError: ('invalid_grant: Bad Request', {'error': 'invalid_grant', 'error_description': 'Bad Request'})

It was challenging to recover from this problem. Running gtasks-md auth "C:\mycred.json" didn't fix the problem. Even after creating a brand new desktop credential and running gtasks-md auth "C:\mycred2.json" the problem persisted.

After manually deleting the cached token via del 'C:\Users\forre\.cache\gtasks-md\default\token.json', then I was able to run gtasks-md auth "C:\mycred2.json", and then my problem was solved.

I am reporting this here in case others have the same problem. Or perhaps there is a bug in the caching logic that it did not automatically get a new token after a token has expired or it that gtasks-md auth didn't clear the cache?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions