【问题标题】:google-translate returns "Invalid JSON payload received"google-translate 返回“收到无效的 JSON 有效负载”
【发布时间】:2017-02-01 17:57:40
【问题描述】:

使用来自 GoogleCloudPlatform\python-docs-samples-master\python-docs-samples-master\translate\cloud-client 的 Python 示例。当我尝试使用 translate-text-with-model 进行翻译时,出现错误

python sn-ps.py translate-text-with-model es "你好吗奶奶" google.cloud.exceptions.BadRequest: 400 收到无效的 JSON 负载。未知名称“模型”:无法绑定“nmt”。在请求消息中找不到字段“模型”。 (GET https://translation.googleapis.com/language/translate/v2?target=es&q=How+are+you+Grandma&model=nmt)

谁能指出我做错了什么?谢谢。

【问题讨论】:

    标签: python google-translate


    【解决方案1】:

    我也遇到了这个问题。我通过将“模型”传递为空来解决了这个问题。我正在使用 PHP,但理论上它应该适用于 Python。

    $translation = $translate->translate($text, [
            'target' => $target,
            'source' => $source,
            'model' => null
        ]);
    

    【讨论】:

    • 但是我们怎么知道我们正在使用神经网络模型进行翻译呢?
    • 您申请参加试用了吗?上次我看它不是开放访问。
    • 是的..我有证书等。感觉有些愚蠢和基本,但无法弄清楚。
    • 嘿 Ramesh,Johnathans 解决方案对您有用吗,或者现在发生了什么?
    【解决方案2】:

    我确定这已经解决了,但我遇到了同样的问题,并意识到 request.json 没有正确指定。

    通过查找当前链接修复您的请求 JSON: https://cloud.google.com/translate/docs/reference/rest/v3/projects.locations/translateText

    我也犯了一个错误,即在 API 版本方面不匹配 JSON。

    我将 JSON 格式用于 v2 Translate API 和 v3 API。

    【讨论】:

      猜你喜欢
      • 2019-12-13
      • 2020-06-26
      • 2020-12-01
      • 1970-01-01
      • 2016-06-19
      • 2018-08-01
      • 2018-04-04
      • 1970-01-01
      • 2017-11-26
      相关资源
      最近更新 更多