terryyin / translate-python

Online translation as a Python module & command line tool. No key, no authentication needed.
MIT License
724 stars 155 forks source link

Microsoft API fails #98

Open mrx23dot opened 2 years ago

mrx23dot commented 2 years ago

translator = Translator(provider='microsoft', secret_access_key='KEY1....', to_lang='eng', from_lang='ch')

fails with

    return ' '.join(self.provider.get_translation(text_wraped) for text_wraped in text_list)
  File "C:\py38_64\lib\site-packages\translate\providers\microsoft.py", line 47, in get_translation
    raise TranslationError(data["error"]["message"])
translate.exceptions.TranslationError: The request is not authorized because credentials are missing or invalid.
MattFellows commented 5 months ago

For future sumblers upon this issue, I had this too - I had to modify the command to pass the region - in fact because I was doing this from the commandline - I had to modify main.py to allow passing the --region flag. Basically when you set up the Translator in Azure you choose a region and unless the Ocp-Apim-Subscription-Region header matches, you get an authentication error.