谷歌云在线词汇表创建返回“空资源名称”错误

问题描述 投票:0回答:1

我正在按照此处指示的确切步骤进行操作 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"
    }
  }
}

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

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

请帮忙。

谢谢。

google-app-engine curl google-cloud-platform google-cloud-firestore google-translate
1个回答
0
投票

我是 Google Cloud 技术支持代表,我们知道目前正在运行的 REST API 存在问题。我尝试重现您的情况,并在尝试直接使用 API 创建术语表时遇到了与您相同的问题。

此后,我尝试使用 HTTP 触发的 Python 云函数以编程方式创建术语表,一切顺利。通过这种方式,您的 API 将通过 Cloud Functions 服务帐户调用。

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

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。这可能是与用于调用此 API 的服务帐户有关的问题。如果这对您不起作用,请告诉我,我会尝试编辑我的评论。

© www.soinside.com 2019 - 2024. All rights reserved.