AttributeError: 'Credentials' object has no attribute 'with_scopes'
See original GitHub issueReproduce:
python3 -m venv cloudsql_env
source cloudsql_env/bin/activate
pip install git+https://github.com/GoogleCloudPlatform/cloud-sql-python-connector@5b02e80149864369a0b8f6bc142d55c278a6e796
ipython
> from google.cloud.sql.connector import connector
> conn = connector.connect("<my-project>:us-central1:sql-1", "pymysql", user="root", password="<my-password", db="<my-db>")
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-2-2f8a588de201> in <module>
4 user="root",
5 password="<>",
----> 6 db="<>")
~/workspace/scio/cloudsql_env/lib/python3.7/site-packages/google/cloud/sql/connector/connector.py in connect(instance_connection_string, driver, **kwargs)
66
67 loop = _get_loop()
---> 68 icm = InstanceConnectionManager(instance_connection_string, loop)
69 return icm.connect(driver, user=kwargs.pop("user"), **kwargs)
~/workspace/scio/cloudsql_env/lib/python3.7/site-packages/google/cloud/sql/connector/InstanceConnectionManager.py in __init__(self, instance_connection_string, loop)
152
153 self._loop = loop
--> 154 self._auth_init()
155 self._priv_key, pub_key = generate_keys()
156 self._pub_key = pub_key.decode("UTF-8")
~/workspace/scio/cloudsql_env/lib/python3.7/site-packages/google/cloud/sql/connector/InstanceConnectionManager.py in _auth_init(self)
373
374 credentials, project = google.auth.default()
--> 375 scoped_credentials = credentials.with_scopes(
376 [
377 "https://www.googleapis.com/auth/sqlservice.admin",
AttributeError: 'Credentials' object has no attribute 'with_scopes'
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (3 by maintainers)
Top Results From Across the Web
GAE AttributeError: 'Credentials' object has no attribute ...
Problem is on GAE, when deployed, the call to with_subject raises: AttributeError: 'Credentials' object has no attribute 'with_subject'.
Read more >AttributeError: 'Credentials' object has no attribute 'authorize'
I am getting following error while deploying the app. I have changed peoject Id in config file. ERROR: (gcloud.app.deploy) Error Response: [9]
Read more >[Python] Gmail API AttributeError: 'Credentials' object has no ...
I'm fairly certain my credentials and permissions are correct, and it's an issue with the code, but I'm really at a loss as...
Read more >google-auth Documentation - Read the Docs
Credentials are the means of identifying an application or user to a service or API. Credentials can be obtained with three different types ......
Read more >OAuth2 scopes - FastAPI
The content of each of these strings can have any format, but should not ... credentials_exception for scope in security_scopes.scopes: if scope not...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I dug into the auth thing. I am going to pass the scope to default. Really, it should avoid a duplication of auth so just a bit cleaner. PR incoming.
Thanks for the quick reply! IIUC, the
Credentials
object that is returned may not have awith_scopes
implementation (see the base class), as it may not be a child ofScoped
. I believe these are the type of Credentials I get when I run with my owner account, as opposed to with a service account. In my case, the credentials creation goes down this path, which is a baseCredentials
object. This is also why if you have a service account activated, or if you’re running on App Engine / GCE this logic is fine.You’re right that the scopes themselves are required – I think
with_scopes_if_required
is a bit of a misleading name.Perhaps a more clear thing to do would be to change
to
here. Note that will result in the same logic in the underlying auth library.