401000 Authentication Error in Microsoft Translator API

Asked 1 years ago, Updated 1 years ago, 342 views

Entering the following code at the MAC terminal results in an error.

Microsoft Azure only configures the Translator in Marketplace and enters the key and the key in the Endpoint column into the Ocp-Apim-Subscription-Key.

Is there anything else to set up?

Will I be able to use it after a while after setting it up?

Once this problem has been cleared, I would like to use it in Python's program.

Thank you for your cooperation.

Commands executed

 curl-X POST "https://api.cognitive.microsofttranslator.com/translate?api-version=3.0&from=en&to=zh-Hans" \
    -H"Ocp-Apim-Subscription-Key:88daf33****"\
    -H"Content-Type: application/json; charset=UTF-8"\
    -d"[{'Text':'Hello, what is your name?'}]"

Error Messages

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

curl

2022-09-30 21:49

1 Answers

Resolved by specifying regions with the following arguments:
(I used it as an official reference, but I also stumbled.)

-H "Ocp-Apim-Subscription-Region:eastasia"

Modified Commands

 curl-X POST "https://api.cognitive.microsofttranslator.com/translate?api-version=3.0&from=en&to=zh-Hans" \
    -H "Ocp-Apim-Subscription-Region:eastasia"\
    - H "Ocp-Apim-Subscription-Key:********"\
    -H"Content-Type: application/json; charset=UTF-8"\
    -d"[{'Text':'Hello, what is your name?'}]"

Reference
https://stackoverflow.com/questions/61573396/translator-text-api-microsoft-azure-always-error-401000


2022-09-30 21:49

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.