googleapis / google-auth-library-python

Google Auth Python Library
https://googleapis.dev/python/google-auth/latest/
Apache License 2.0
771 stars 305 forks source link

AttributeError: 'dict' object has no attribute 'authorize' error after having moved to google.oauth2.credentials.Credentials #1400

Closed andreamoro closed 10 months ago

andreamoro commented 10 months ago

Environment details

Steps to reproduce

I've been trying to upgrade my code from the deprecated oauth2client.client.OAuth2Credentials to google.oauth2.credentials.Credentials without success as I continue to get the authorize attribute error being missing despite having upgraded all the librarie. Note: Although I created a brand new environment, after the first pip install I had to upgrade some libraries as there were not aligned with the above details.

That said, after having obtained a token with a flow object, I then get a credential object via the google.oauth2.credentials.Credentials (successfully)

image

However, by the time I pass the credentials along with the API version and name to the discovery.build method, I get the following AttributeError message.

image

See below the incriminated code:

        API_SERVICE_NAME = 'searchconsole'
        API_VERSION = 'v1'

        search_console_service = discovery.build(
            API_SERVICE_NAME, API_VERSION, credentials=credentials)

and credentials dictionary

    'token': 'redacted'
    'refresh_token': 'redacted'
    'client_id': 'redacted'
    'client_secret': 'redacted'
    'token_uri': 'https://accounts.google.com/o/oauth2/token'
    'scopes': 'https://www.googleapis.com/auth/webmasters.readonly'

Any idea of what's wrong? Thanks!

clundin25 commented 10 months ago

Hey can you share a sample that reproduces this issue? It is hard to follow the flow in this query.

andreamoro commented 10 months ago

Actually, ignore me. I just realised even from the small things above, that I was no longer passing the authenticated credential objects to the build method but my dictionary. Apologies for the confusion.