google 云在线词汇表创建返回 "empty resource name" 错误

google cloud online glossary creation returning "empty resource name" error

我正在按照此处指示的确切步骤进行操作 https://cloud.google.com/translate/docs/glossary#create-glossary

创建在线词汇表。

我收到以下错误

madan@cloudshell:~ (focused-pipe-251317)$ ./rungcglossary
{
  "error": {
    "code": 400,
    "message": "Empty resource name.;  Resource type: glossary",
    "status": "INVALID_ARGUMENT"
  }
}

这是我的正文request.json

{
  "languageCodesSet": {
    "languageCodes": ["en", "en-GB", "ru", "fr", "pt-BR", "pt-PT", "es"]
  },
  "inputConfig": {
    "gcsSource": {
"inputUri": "gs://focused-pipe-251317-vcm/testgc.csv"
    }
  }
}

我从 google 云存储桶文件 URI 框中复制的 inputUri 路径。

我无法理解问题所在。我所知道的是 inputUri 字符串有问题。

请帮忙。

谢谢。

我是一名 Google 云技术支持代表,我们知道,目前,REST API 存在一个问题,该问题正在进行中。我试图重现您的情况,并在尝试直接使用 API 创建词汇表时遇到了与您相同的问题。

之后,我尝试使用 HTTP 触发 Python Cloud Function 以编程方式创建词汇表,一切都很顺利。通过这种方式,您的 API 将使用 Cloud Functions 服务帐户进行调用。

我将附上我的 Python 云函数的代码:

from google.cloud import translate_v3beta1 as translate
def create_glossary(request):

request_json = request.get_json()
client = translate.TranslationServiceClient()
## Set your project name
project_id = 'your-project-id'
## Set your wished glossary-id
glossary_id = 'your-glossary-id'
## Set your location
location = 'your-location'  # The location of the glossary

name = client.glossary_path(
    project_id,
    location,
    glossary_id)

language_codes_set = translate.types.Glossary.LanguageCodesSet(
    language_codes=['en', 'es'])
## SET YOUR BUCKET URI
gcs_source = translate.types.GcsSource(
    input_uri='your-gcs-source-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 = client.location_path(project_id, location)

operation = client.create_glossary(parent=parent, glossary=glossary)

result = operation.result(timeout=90)
print('Created: {}'.format(result.name))
print('Input Uri: {}'.format(result.input_config.gcs_source.input_uri))

requirements.txt 应包括以下依赖项:

google-cloud-translate==1.4.0
google-cloud-storage==1.14.0

别忘了用你的参数修改代码

基本上,我只是遵循了与您相同的教程,但是 Python 并且我使用了 Cloud Functions。我的猜测是您可以使用 App Engine Standard,因为 well.This 可能是与用于调用此 API 的服务帐户有关的问题。如果这对您不起作用,请告诉我,我会尝试编辑我的评论。