1

I'm new to programming, and have been trying to use Google Translate API. I'm running into this issue and have tried to find a solution to no avail. I've created a Google Service Account, and Key. I'm on a Mac inside Jupyter Notebook.

Error:

~/opt/anaconda3/lib/python3.7/site-packages/google/cloud/client.py in __init__(self, credentials, _http, client_options) 141 raise ValueError(_GOOGLE_AUTH_CREDENTIALS_HELP) 142 --> 143 scopes = client_options.scopes or self.SCOPE 144 145 # if no http is provided, credentials must exist AttributeError: 'ClientOptions' object has no attribute 'scopes' 

My Code:

import os from google.cloud import translate_v2 os.environ["GOOGLE_APPLICATION_CREDENTIALS"]="cloud_key.json" translate_client = translate.Client() 
2

1 Answer 1

1

I tried the example with the latest updated libraries, and it works for me.

Nevertheless, if the inferred credentials are not properly handled, you can pass explicit credentials to the client:

from google.cloud import translate_v2 as translate from google.oauth2 import service_account credentials = service_account.Credentials.from_service_account_file('/path/to/key.json') scoped_credentials = credentials.with_scopes(['https://www.googleapis.com/auth/cloud-platform']) translate_client = translate.Client(credentials=scoped_credentials) 

More details about creating explicit credentials in here (this answer is pretty much a copy of the instructions on that doc).

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.