Skip to content

Instantly share code, notes, and snippets.

@mathjazz
Created May 30, 2023 10:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mathjazz/fb49e0f8b3dbf17fe8333c235fadfb9c to your computer and use it in GitHub Desktop.
Save mathjazz/fb49e0f8b3dbf17fe8333c235fadfb9c to your computer and use it in GitHub Desktop.
>>> from google.cloud import translate_v3 as translate
>>>
>>> client = translate.TranslationServiceClient()
>>>
>>> project_id = "pontoon-prod"
>>> input_uri = "gs://pontoon-prod-model-data-c1107144/glossary.csv"
>>> timeout = 180
>>>
>>> source_lang_code = "en"
>>> target_lang_code = "sl"
>>> location = "us-central1"
>>>
>>> name = client.glossary_path(project_id, location, "glossary_id")
>>>
>>> language_codes_set = translate.types.Glossary.LanguageCodesSet(
... language_codes=[source_lang_code, target_lang_code]
... )
>>>
>>> gcs_source = translate.types.GcsSource(input_uri=input_uri)
>>> input_config = translate.types.GlossaryInputConfig(gcs_source=gcs_source)
>>>
>>> glossary = translate.types.Glossary(
... name=name, language_codes_set=language_codes_set, input_config=input_config
... )
>>>
>>> parent = f"projects/{project_id}/locations/{location}"
>>>
>>> operation = client.create_glossary(parent=parent, glossary=glossary)
Traceback (most recent call last):
File "/usr/local/lib/python3.9/site-packages/google/api_core/grpc_helpers.py", line 72, in error_remapped_callable
return callable_(*args, **kwargs)
File "/usr/local/lib/python3.9/site-packages/grpc/_channel.py", line 946, in __call__
return _end_unary_response_blocking(state, call, False, None)
File "/usr/local/lib/python3.9/site-packages/grpc/_channel.py", line 849, in _end_unary_response_blocking
raise _InactiveRpcError(state)
grpc._channel._InactiveRpcError: <_InactiveRpcError of RPC that terminated with:
status = StatusCode.PERMISSION_DENIED
details = "Cloud IAM permission 'cloudtranslate.glossaries.create' denied. "
debug_error_string = "UNKNOWN:Error received from peer ipv4:142.251.39.74:443 {created_time:"2023-05-30T10:43:42.428807878+00:00", grpc_status:7, grpc_message:"Cloud IAM permission \'cloudtranslate.glossaries.create\' denied. "}"
>
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/usr/local/lib/python3.9/site-packages/google/cloud/translate_v3/services/translation_service/client.py", line 1454, in create_glossary
response = rpc(
File "/usr/local/lib/python3.9/site-packages/google/api_core/gapic_v1/method.py", line 154, in __call__
return wrapped_func(*args, **kwargs)
File "/usr/local/lib/python3.9/site-packages/google/api_core/grpc_helpers.py", line 74, in error_remapped_callable
raise exceptions.from_grpc_error(exc) from exc
google.api_core.exceptions.PermissionDenied: 403 Cloud IAM permission 'cloudtranslate.glossaries.create' denied.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment