Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Issue with Deleting Glossaries in Google Cloud Translation API: InvalidArgument Error

Hello,

I am experiencing an issue with the Google Cloud Translation API when trying to delete glossaries programmatically. Specifically, when I use the delete_glossary function to delete an existing glossary, I receive an InvalidArgument error, and the glossary is not deleted.

Issue Details:

I am using the following code to delete a glossary:

from google.cloud import translate_v3beta1 as translate
from google.api_core.exceptions import DeadlineExceeded
from google.oauth2.service_account import Credentials

def delete_glossary(    source_lang,
    target_lang,
    timeout: int = 180,):
    credentials = Credentials.from_service_account_file('service_account.json')
    client = translate.TranslationServiceClient(credentials=credentials)

    GLOSSARY_PREFIX = "GLOSSARY_PREFIX" # Replaced with actual prefix
    PROJECT_ID = "PROJECT_ID"  # Replaced with actual project ID
    glossary_id = f"{GLOSSARY_PREFIX}_{source_lang}_{target_lang}"
    name = client.glossary_path(PROJECT_ID, "us-central1", glossary_id)

    try:
        operation = client.delete_glossary(name=name)
        result = operation.result(timeout)
        print(f"Deleted Success: {result.name}")

    except DeadlineExceeded:
        print(f"Deadline Exceeded. Retry Deleting Glossary: {glossary_id}")
        delete_glossary(source_lang, target_lang)

    except Exception as e:
        print(f"Deleted Error: {name}")
        print(f"Error details: {e}")

I receive the following error:

Deleted Error: projects/PROJECT_ID/locations/us-central1/glossaries/GLOSSARY_PREFIX_ko_xh 
400 Request contains an invalid argument.
<class 'google.api_core.exceptions.InvalidArgument'>

To verify that the glossary exists, I used the following code to list glossaries.

The output confirms that the glossary exists:

Name: projects/PROJECT_ID/locations/us-central1/glossaries/GLOSSARY_PREFIX_ko_xh

Troubleshooting Steps Taken:

  • Verified PROJECT_ID: Ensured that the PROJECT_ID variable is correctly set.
  • Checked Location: Confirmed that the glossary is in the us-central1 location.
  • Service Account Permissions: Verified that the service account has the Cloud Translation API Admin role.
  • Language Codes: Checked that the language codes ko (Korean) and xh (Xhosa) are supported by the Translation API and the glossary feature.

Despite these steps, the InvalidArgument error persists, and I am unable to delete the glossary programmatically.

Questions:

  1. Is this a known issue with the Google Cloud Translation API?
  2. How can I resolve the InvalidArgument error and successfully delete the glossary using the API?
  3. Are there any additional steps or considerations I might have overlooked?

Any assistance or guidance on this matter would be greatly appreciated.

Thank you.

1 3 276
3 REPLIES 3

Hello
I am expect that you cannot deleted translation API.because translations
fix on application.
Regard

Hey @kwkang , I had exactly same issue by keep saying "Request contains an invalid argument"

This was actually, google cloud permission issue and they recently releases new update here  Oct 4 

Solution:  you should try from same region with your project root region.  In your case "us-central1"

in addition.
we have multiple regions in our system and google project root is in us-central1 region.
So, we were trying to create a glossary from region [kr server]. So, I switched to US region and it worked. 




 

Hello everyone,

I wanted to provide an update regarding the issue I was experiencing. I tried again over the past weekend, and the problem has disappeared. The delete_glossary function is now working as expected, and I am able to delete glossaries without any errors.

Thank you all for your assistance and suggestions. Your help was greatly appreciated.

Best regards,