Forums

Real Time Translation With Microsoft Azure Translator API

Hello,

I'm trying to set up the Micrsofot Azure Translator API for live translation of posts added by users on my website. This is part of the Flask Mega-Tutorial by Miguel Grinberg, which I'm following.

I sticked closely to the instructions and code of the tutorial and managed to test my function from a Python console. I'm calling it with a string that should be translated, the language that the text is wrtitten in, the language in which the text should be translated, and I'm getting the translated string as output.

However, when I'm trying to invoke the function from my Website, I'm getting an errormessage, that tells me that the authentication failed. To be exact, it fails this if-clause:

if 'MS_TRANSLATOR_KEY' not in app.config or not app.config['MS_TRANSLATOR_KEY']:

I've exported the MS_TRANSLATOR_KEY into my virtual environment and I'm referencing it from my config.py-file like so:

MS_TRANSLATOR_KEY = os.environ.get('MS_TRANSLATOR_KEY')

I've already checked the Quickstartguide here Quickstart: Azure Cognitive Services Translator REST APIs and I can't find any reason why it's not working. So I wonder if it has anything to to with PythonAnywhere? Might the authentication-process be blocked when invoked by a clients browser?

Thank you for your help in advance!

Best,

Thomas

Take a look at https://help.pythonanywhere.com/pages/environment-variables-for-web-apps

Loading my .env file into the WSGI configuration file fixed the issue :)

Thanks for sharing the link to this help page!

Glad to hear that you made it!