unable to find "application" callable in file /app/webapp.py
See original GitHub issueI am converting a flask application to Docker using uwsgi-nginx-flask-docker. I am using flask_restful to support a restful interface only.
Here are the relevant parts of my webapp.py (equivalent of main.py in the example):
#!flask/bin/python
import os, sys; sys.path.append(os.path.dirname(os.path.realpath(__file__)))
from flask import Flask, jsonify, make_response
from flask_restful import Api
from flask_cors import CORS
from actual_app.frontend import resources, useradmin, entityadmin
from flask_jwt_extended import JWTManager
import logging, logging.handlers
app = Flask(__name__, static_folder='static', static_url_path='')
app.config['CORS_HEADERS'] = 'Content-Type'
cors = CORS(app, resources={r"/api": {"origins": "http://localhost"}})
logging.basicConfig(level=logging.INFO)
app.debug = True
app.config['SECRET_KEY'] = 'app-is-cool'
app.config['JWT_ACCESS_LIFESPAN'] = {'hours': 24}
app.config['JWT_REFRESH_LIFESPAN'] = {'days': 30}
jwt = JWTManager(app)
api = Api(app)
api.add_resource(resources.Login, '/api/login', methods=['POST'])
api.add_resource(resources.Logout, '/api/logout', methods=['POST'])
api.add_resource(resources.RegisterOtp, '/api/register_otp', methods=['POST'])
...
@app.route('/', methods=['POST', 'GET'])
def index():
return "<h1>Example Limited</h1>"
@app.errorhandler(404)
def not_found(error):
return make_response(jsonify({'error': 'Not found'}), 404)
@app.errorhandler(500)
def server_error(e):
logging.exception('An error occurred during a request. %s', e)
return "An internal error occurred", 500
if __name__ == '__main__':
app.run(host='0.0.0.0', debug=True, port=80, use_reloader=False)
I run it as docker run --name app_name -d -e URL=http://localhost -e EMAIL=Dev -e CLIENT=dev -e CACHE="1 Month" -v /datanew:/datanew -p 80:80 --rm myapp/web:v01
I have the Flask application named ‘app’ as required but get this error:
unable to find "application" callable in file /app/webapp.py
unable to load app 0 (mountpoint='') (callable not found or import error)
*** no app loaded. GAME OVER ***
Ideas on what might be wrong?
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
uWSGI cannot find "application" using Flask and Virtualenv
unable to find "application" callable in file /var/www/coefficient/flask.py. is the key :) Your app is defining an 'app' callable, ...
Read more >python - Flask and uWSGI - unable to load app 0 (mountpoint ...
I had problems with the accepted solution because my flask app was in a variable called app . You can solve that with...
Read more >Django+uWsgi unable to find "application" callable
The error is telling you that it can't find that variable name. And yet, you clearly are defining it.
Read more >Bug listing with status CONFIRMED as at 2022/12/20 18:46:38
config file verification" status:CONFIRMED resolution: severity: ... Bug:75028 - "app-editors/xemacs-21.4.21-r1 fails to build: Segmentation fault" ...
Read more >Newbie, first script isn't working - Remotify
File "/Applications/Ableton Live 11 ... Remote Scripts/test/__init__.py", line 4, in create_instance ... 'module' object is not callable
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

The problem is that the image is not being able to find your Flask app. The module in this case is
webapp, by the error, it seems you seem to have that correctly set. But the callable is notapplication, butapp. The callable is the variable with the Flask app.Check the docs here: https://github.com/tiangolo/uwsgi-nginx-flask-docker#custom-uwsgiini-configurations
This is what I think your
/app/uwsgi.inifile should look like:About migrating to FastAPI, I guess that code could look like:
That would expect a JSON like:
And the dependency
get_current_userwould be re-usable and would extract the JWT as described here: https://fastapi.tiangolo.com/tutorial/security/oauth2-jwt/If you want to separate all the HTTP methods for
/register-otp/, you could put them in a single Python file (a Python module), with a “router”, and then include them using the prefix URL/register_otp.In that case, that would look like:
Notice the
@app.post("/")without/register_otp/.And your docs would look like:
Great! Thanks for reporting back and closing the issue.