1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Python] GoogleAuth getting "invalid grant: Bad Request" in call to LocalWebserverAuth()

Discussão em 'Python' iniciado por Stack, Outubro 7, 2024 às 11:13.

  1. Stack

    Stack Membro Participativo

    Here's a Python script in its entirety:

    from pydrive.auth import GoogleAuth

    gauth = GoogleAuth()
    gauth.LoadClientConfigFile("client_secrets.json")
    print(f'==== called LoadClientConfigFile', flush=True)
    gauth.LocalWebserverAuth() # Prompt for authentication via web browser


    When I run it, I get the following:

    ==== called LoadClientConfigFile
    Traceback (most recent call last):
    File "C:\Users\r\.virtualenvs\pygmu-oJfXpe_C\Lib\site-packages\pydrive\auth.py", line 475, in Refresh
    self.credentials.refresh(self.http)
    File "C:\Users\r\.virtualenvs\pygmu-oJfXpe_C\Lib\site-packages\oauth2client\client.py", line 545, in refresh
    self._refresh(http)
    File "C:\Users\r\.virtualenvs\pygmu-oJfXpe_C\Lib\site-packages\oauth2client\client.py", line 761, in _refresh
    self._do_refresh_request(http)
    File "C:\Users\r\.virtualenvs\pygmu-oJfXpe_C\Lib\site-packages\oauth2client\client.py", line 819, in _do_refresh_request
    raise HttpAccessTokenRefreshError(error_msg, status=resp.status)
    oauth2client.client.HttpAccessTokenRefreshError: invalid_grant: Bad Request

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
    File "C:\Users\r\Projects\pygmu\t1.py", line 6, in <module>
    gauth.LocalWebserverAuth() # Prompt for authentication via web browser
    ^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "C:\Users\r\.virtualenvs\pygmu-oJfXpe_C\Lib\site-packages\pydrive\auth.py", line 120, in _decorated
    self.Refresh()
    File "C:\Users\r\.virtualenvs\pygmu-oJfXpe_C\Lib\site-packages\pydrive\auth.py", line 477, in Refresh
    raise RefreshError('Access token refresh failed: %s' % error)
    pydrive.auth.RefreshError: Access token refresh failed: invalid_grant: Bad Request


    Given that the error happens after the call to LoadClientConfigFile(), I suspect the issue might be with the call to LocalWebserverAuth().

    Any ideas on how to diagnose and/or fix this?

    Update


    Note that no web server window appears, so I'm not sure where the problem lies.

    Environment

    • Python 3.12
    • Windows 11 Pro, v 23H2
    • Available Browser(s): Firefox, Chrome, Edge
    Update 2


    Based on a hint from @LindaLawton-DaImTo, my code may be out of date. I'm revisiting https://developers.google.com/drive/api/guides/about-sdk and https://developers.google.com/drive/api/quickstart/js to make sure I'm using the current API. Standby...

    Continue reading...

Compartilhe esta Página