0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Azure AI 翻訳 の API で401001 エラーになる

Posted at

以下ドキュメント通りに REST API の実行を試すとエラーになる

エラー内容
{"error":{"code":401001,"message":"The request is not authorized because credentials are missing or invalid."}}

※英語版でもダメなのでドキュメントが仕様に追いついていないのだと思われる

ドキュメントの curl 例
curl -X POST "https://api.cognitive.microsofttranslator.com/translate?api-version=3.0&from=en&to=zh-Hans" \
-H "Ocp-Apim-Subscription-Key: <client-secret>"  \
-H "Content-Type: application/json; charset=UTF-8" \
-d "[{'Text':'Hello, what is your name?'}]"
修正版 curl(Japan East リージョンのリソースの場合)
curl -X POST "https://api.cognitive.microsofttranslator.com/translate?api-version=3.0&from=en&to=zh-Hans" \
-H "Ocp-Apim-Subscription-Key: <client-secret>"  \
-H "Ocp-Apim-Subscription-Region: japaneast"  \
-H "Content-Type: application/json; charset=UTF-8" \
-d "[{'Text':'Hello, what is your name?'}]"

// Cloud Shell での実行結果
image.png

後で気づいたけど、こっちのドキュメントにはちゃんと書いてあるのな

正しく動作するcurl例
// Pass secret key and region using headers to a custom endpoint
curl -X POST "https://my-swiss-n.cognitiveservices.azure.com/translator/text/v3.0/translate?to=fr" \
-H "Ocp-Apim-Subscription-Key: xxx" \
-H "Ocp-Apim-Subscription-Region: switzerlandnorth" \
-H "Content-Type: application/json" \
-d "[{'Text':'Hello'}]" -v
```bash:修正版curl
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?