I am trying to use the Google DocAI Warehouse sample Python code and it looks like that the location parameter is always ignored and just assumes the 'us' location.

My prototype project has 'eu' as location and the sample code simply fails:

google.api_core.exceptions.InvalidArgument: 400 The resource projects/{my-proj-id}/locations/eu is not located in us

This issue is highlighted here https://github.com/GoogleCloudPlatform/document-ai-samples/issues/676 and https://www.googlecloudcommunity.com/gc/AI-ML/Document-AI-Warehouse-API-Sample-Python-Code-location-eu-Issue/td-p/677608 but no responses.

Just wondering if anyone on here can help?

1

There are 1 best solutions below

0
On

The Python and Node.js samples don't include the endpoint override required for non-US instances.

This can be done with ClientOptions similar to this sample for Document AI.

Here's what it should look like for Document AI Warehouse in Python.

from google.api_core.client_options import ClientOptions
from google.cloud import contentwarehouse

# TODO(developer): Uncomment these variables before running the sample.
# project_number = "YOUR_PROJECT_NUMBER"
# location = "YOUR_PROJECT_LOCATION"  # Format is "us" or "eu"
# user_id = "user:[email protected]"  # Format is "user:[email protected]"


def quickstart(project_number: str, location: str, user_id: str) -> None:
    # You must set the `api_endpoint` if you use a location other than "us".
    client_options = (
        ClientOptions(api_endpoint=f"{location}-contentwarehouse.googleapis.com")
        if location != "us"
        else None
    )
    # Create a Schema Service client
    document_schema_client = contentwarehouse.DocumentSchemaServiceClient(
        client_options=client_options
    )

    # ...

    # Create a Document Service client
    document_client = contentwarehouse.DocumentServiceClient(
        client_options=client_options
    )

    # ... Rest of the code is unchanged

I have these Pull Requests open to update the code samples: