gpt4 book ai didi

azure - 无法让 Microsoft Translator API 字典查找工作

转载 作者:行者123 更新时间:2023-12-02 08:32:46 27 4
gpt4 key购买 nike

我订阅了免费的 Azure 试用版以使用字典查找功能并获得了此端点和(已编辑的)API key :

Grab your keys and endpoint

key1

084***13

Endpoint

https://westeurope.api.cognitive.microsoft.com/

Every call to Cognitive Services requires the subscription key above. This key needs to be either passed through a query string parameter or specified in the request header. To manage your keys, use the Keys option from the left menu

然后this page我找到一个简单的例子,似乎我只需要替换 key :

curl -X POST "https://api.cognitive.microsofttranslator.com/dictionary/lookup?api-version=3.0&from=en&to=es" -H "Ocp-Apim-Subscription-Key: <client-secret>" -H "Content-Type: application/json" -d "[{'Text':'fly'}]"

我在命令行中测试它,替换 key ,但没有成功:

curl -X POST "https://api.cognitive.microsofttranslator.com/dictionary/lookup?api-version=3.0&from=en&to=es" -H "Ocp-Apim-Subscription-Key: 084***13" -H "Content-Type: application/json" -d "[{'Text':'fly'}]

{"error":{"code":401000,"message":"The request is not authorized because credentials are missing or invalid."}}

我尝试更改端点,但也没有成功:

curl -X POST "https://westeurope.api.cognitive.microsoft.com/dictionary/lookup?api-version=3.0&from=en&to=es" -H "Ocp-Apim-Subscription-Key: 084***13" -H "Content-Type: application/json" -d "[{'Text':'fly'}]

{"error":{"code":"404","message": "Resource not found"}}

我认为我遗漏了一些明显的东西,但该文档对新手并不友好。我该怎么办?

最佳答案

您需要添加一个区域!

这取决于您订阅的资源,因为有 2 个选项,Translator Text APICognitive Services multi-service API

我可以看到你选择了 Cognitive Services multi-service因此,在这种情况下,您需要添加 Ocp-Apim-Subscription-Region documentation 中规定的值

When you use a multi-service secret key, you must include two authentication headers with your request. The first passes the secret key, the second specifies the region associated with your subscription.

  • Ocp-Apim-Subscription-Key
  • Ocp-Apim-Subscription-Region

我在下面添加了它,你只需替换 <your-key><your-region>用你自己的!

curl -X POST "https://api.cognitive.microsofttranslator.com/dictionary/lookup?api-version=3.0&from=en&to=es" -H "Ocp-Apim-Subscription-Key: <your-key>" -H "Ocp-Apim-Subscription-Region: <your-region>" -H "Content-Type: application/json" -d "[{'Text':'fly'}]"

关于azure - 无法让 Microsoft Translator API 字典查找工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59423805/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com