Forums

Import Error with Flask while deploying Auth0

Hi all, I am a beginner python programmer. I am trying to deploy a Flask webpage with Auth0 authentication. I started to follow the description on Auth0's page, but I keep receiving this error message:

2017-11-23 20:22:42,008: Error running WSGI application
2017-11-23 20:22:42,049: ModuleNotFoundError: No module named 'dotenv'
2017-11-23 20:22:42,049:   File "/var/www/ecokarst_pythonanywhere_com_wsgi.py", line 16, in <module>
2017-11-23 20:22:42,049:     from flask_app import app as application
2017-11-23 20:22:42,049: 
2017-11-23 20:22:42,049:   File "/home/ecokarst/mysite/flask_app.py", line 7, in <module>
2017-11-23 20:22:42,050:     from dotenv import load_dotenv, find_dotenv

Does anyone has an idea how to fix this issue?

I installed the "python-dotenv" module with pip (tried both normally and in a virtualenv) still I get the import error message.

I guess I should somehow edit my "ecokarst_pythonanywhere_com_wsgi.py" file, but cannot find any information to this.

Alternatively, does anyone has a working hello-world style example with Flask + Auth0 on PythonAnywhere?

Thanks in advance

Are you looking at the right part of the error log? The message you posted above came from 23 November, so a few days ago. The most recent errors in the log are at the bottom of the file.

Oh. You are right.

Here is the right error:

2017-11-27 12:51:45,266: Error running WSGI application
2017-11-27 12:51:45,267:   File "/home/ecokarst/mysite/flask_app.py", line 41
2017-11-27 12:51:45,267: 
2017-11-27 12:51:45,267:     payload = jwt.decode(id_token, jwks.read(), algorithms=['RS256'], audience=XXX,
2017-11-27 12:51:45,267: 
2017-11-27 12:51:45,268:                                                                                                               ^
2017-11-27 12:51:45,268: 
2017-11-27 12:51:45,268: SyntaxError: invalid syntax
2017-11-27 12:51:45,268:   File "/var/www/ecokarst_pythonanywhere_com_wsgi.py", line 16, in <module>
2017-11-27 12:51:45,268:     from flask_app import app as application
2017-11-27 12:51:45,268: ***************************************************
2017-11-27 12:51:45,268: If you're seeing an import error and don't know why,
2017-11-27 12:51:45,269: we have a dedicated help page to help you debug: 
2017-11-27 12:51:45,269: https://help.pythonanywhere.com/pages/DebuggingImportError/
2017-11-27 12:51:45,269: ***************************************************

The full code where the error is coming from can be read here. (I have changed the auidience to XXX)

Unfortunately it looks like the error is in the bit that you had to replace with "XXX" (which was the right thing to do, of course -- you don't want to post private information on these public forums).

I had a look at our system logs, where the same error is repeated, and it looks like you're missing quotes around the value for "audience".

Looks better now, thanks.

Excellent -- thanks for confirming.