Hello all and Happy Holidays,
I am trying to serve a flask application via wsgi and nginx, because I read it's a much more safer way. I am currently following this guide -> https://www.rosehosting.com/blog/how-to-deploy-flask-application-with-nginx-and-gunicorn-on-ubuntu-20-04/
I have Ubuntu 22.04. The problem is that when i execute
FLASK_ENV=developmnent FLASK_APP=server.py flask run
everything works fine and I can access the hostname with no problems. According the guide, to assure that everything works perfectly, I need to execute the server.py script via python3 command too. When I do that I get the following error:
File "../server/venv/lib/python3.10/site-packages/flask_restplus/api.py", line 215, in __getattr__
return getattr(self.default_namespace, name)
AttributeError: 'Namespace' object has no attribute 'run'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "../server/server.py", line 317, in <module>
app.run(host='0.0.0.0')
File "../server/venv/lib/python3.10/site-packages/flask_restplus/api.py", line 217, in __getattr__
raise AttributeError('Api does not have {0} attribute'.format(name))
AttributeError: Api does not have run attribute
Below you can view my server.py:
### IMPORTS ###
### GLOBAL VARIABLES ###
### FLASK CONFIGURATION ###
flask_app = Flask(__name__)
flask_app.secret_key = '...'
authorizations = { # AAI
'apikey': {
'type': 'apiKey',
'in': 'header',
'name': 'X-API-KEY'
}
}
app = Api(app = flask_app, authorizations=authorizations,
version = "1.1",
title = "Title",
description = "desc"
api = app.namespace('psa-controller', description='desc')
### FLASK CONFIGURATION ###
### MODEL ###
### UPLOAD PARSER ###
upload_parser = api.parser()
upload_parser.add_argument('file', location='files', required=True, type=FileStorage, help="Acceptable extensions: ['png', 'jpg', 'jpeg']")
### UPLOAD PARSER ###
### METHODS ###
### CONTROLLERS ###
### RUN ###
if __name__ == '__main__':
app.run(host='0.0.0.0')
### RUN ###
#%%
Not sure why the python execution gets me an error while the flask doesn't (or surpresses it).
I've finished the guide successfully with the demo flaskapp.py, so I guess I need to get over my errors to continue first. Any help would be awesome!
Thank you