google-api-python-client icon indicating copy to clipboard operation
google-api-python-client copied to clipboard

Google Cloud AI Platform Optimizer API is completely broken when constructed using discovery.build("ml", "v1")

Open Ark-kun opened this issue 4 years ago • 3 comments

Thanks for stopping by to let us know something could be better!

If you are still having issues, please be sure to include as much information as possible:

Environment details

  • OS type and version: Linux
  • google-api-python-client version: pip show google-api-python-client

Code example

from googleapiclient import discovery
ml_v1 = discovery.build("ml", "v1")
ml_v1.projects().locations().studies().list(parent='projects/<my-project>/locations/us-central1').execute()

Stack trace

---------------------------------------------------------------------------
HttpError                                 Traceback (most recent call last)
<ipython-input-7-35c4fabe04d6> in <module>
----> 1 ml_v1_projects_locations_studies.list(parent='projects/140626129697/locations/us-central1').execute()

/opt/conda/lib/python3.7/site-packages/googleapiclient/_helpers.py in positional_wrapper(*args, **kwargs)
    129                 elif positional_parameters_enforcement == POSITIONAL_WARNING:
    130                     logger.warning(message)
--> 131             return wrapped(*args, **kwargs)
    132 
    133         return positional_wrapper

/opt/conda/lib/python3.7/site-packages/googleapiclient/http.py in execute(self, http, num_retries)
    935             callback(resp)
    936         if resp.status >= 300:
--> 937             raise HttpError(resp, content, uri=self.uri)
    938         return self.postproc(resp, content)
    939 

HttpError: <HttpError 501 when requesting https://ml.googleapis.com/v1/projects/140626129697/locations/us-central1/studies?alt=json returned "Operation is not implemented, or supported, or enabled.". Details: "Operation is not implemented, or supported, or enabled.">

The main issue is that baseUrl is "https://ml.googleapis.com/" instead of "https://us-central1-ml.googleapis.com/".

The https://us-central1-ml.googleapis.com/$discovery/rest?version=v1 discovery doc has this problem as well.

Can you please fix this or send it to the relevant Google teams, so that they fix their discovery docs.

Ark-kun avatar Aug 02 '21 00:08 Ark-kun

Hi @Ark-kun,

You can change the effective base URl with the api_endpoint client option.

https://cloud.google.com/ai-platform/prediction/docs/regional-endpoints#python

from google.api_core.client_options import ClientOptions
from googleapiclient import discovery

endpoint = 'https://REGION-ml.googleapis.com'
client_options = ClientOptions(api_endpoint=endpoint)
ml = discovery.build('ml', 'v1', client_options=client_options)

@vinnysenthil Do the Vertex AI folks also cover this API? Is this a problem you're familiar with? It seems odd to me that a method doesn't work with the global endpoint.

busunkim96 avatar Aug 02 '21 16:08 busunkim96

Googlers see b/196056955

parthea avatar Aug 10 '21 17:08 parthea