error: 401000 Authorization error - Azure Translator

Aaron 1 Reputation point
2021-07-26T13:55:17.867+00:00

For some reason I am getting this error from endpoint:

 {'error': {'code': 401000, 'message': 'The request is unauthorized because credentials are missing or invalid.'}}  

I did nothing, any kind of change, the script done in python (3.6) was working correctly and then I started getting this error about authorization.

Tried some changes like, use endpoint for my region (westeurope), renew key, use second key, even used alternative method with "Authorization: Bearer key" instead of "Ocp-Apim-Subscription-Key" like documentation says but nothing works.

Here are the screenshots with the settings I hope someone can help me, thanks.

118001-image.png

117964-image.png

Azure Translator
Azure Translator
An Azure service to easily conduct machine translation with a simple REST API call.
408 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. GiftA-MSFT 11,171 Reputation points
    2021-07-26T23:03:51.703+00:00

    Hi, thanks for reaching out. Please try the following sample code (resource region is West Europe):

    import requests  
    import json  
      
    url = "https://api-eur.cognitive.microsofttranslator.com/translate?api-version=3.0&to=fr"  
      
    payload = json.dumps([  
      {  
        "Text": "Hello, what is your name?"  
      }  
    ])  
    headers = {  
      'Ocp-Apim-Subscription-Key': 'ENTER KEY',  
      'Content-Type': 'application/json',  
      'Ocp-Apim-Subscription-Region': 'westeurope'  
    }  
      
    response = requests.request("POST", url, headers=headers, data=payload)  
      
    print(response.text)  
    

    Output:

    117988-image.png

    0 comments No comments

  2. Aaron 1 Reputation point
    2021-07-27T11:21:05.853+00:00

    Still getting the same error:

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

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.