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()
Donnald Cucharo
  • 3,866
  • 1
  • 10
  • 17
Parry Chen
  • 29
  • 2
  • You can check this thread https://stackoverflow.com/a/63287810/8835357 – specbug Oct 05 '20 at 15:32
  • Does this answer your question? [Google cloud storage python client AttributeError: 'ClientOptions' object has no attribute 'scopes' occurs after deployment](https://stackoverflow.com/questions/63278444/google-cloud-storage-python-client-attributeerror-clientoptions-object-has-no) – Dustin Ingram Oct 06 '20 at 17:58

1 Answers1

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).

Jofre
  • 3,718
  • 1
  • 23
  • 31