googletranslate返回“接收到无效的JSON负载”

2024-09-28 21:39:21 发布

您现在位置:Python中文网/ 问答频道 /正文

使用来自GoogleCloudPlatform\Python docs samples master\Python docs samples master\translate\cloud client中的Python示例。当我试图使用翻译文本和模型进行翻译时,我得到了错误

python snippets.py translate-text-with-model es "How are you Grandma" google.cloud.exceptions.BadRequest: 400 Invalid JSON payload received. Unknown name "model": Cannot bind 'nmt'. Field 'model' could not be found in request message. (GET https://translation.googleapis.com/language/translate/v2?target=es&q=How+are+you+Grandma&model=nmt)

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


Tags: masterclientyoucloud示例docsmodeles
2条回答

我也遇到了这个问题。我通过传递'model'为null来解决这个问题。我使用的是PHP,但理论上它应该适用于Python。在

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

我确信这个问题已经解决了,但我也面临着同样的问题,我意识到请求.json未正确指定。在

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

另外,我犯了一个错误,即没有将JSON与API版本相匹配。在

我对v2 Translate API和v3api使用了JSON格式。在

相关问题 更多 >