unable to load app 0 (mountpoint='') - Flask app with uwsgi - python

I have a python flask app in below structure
Admin
|-app
| -__init__.py
|-wsgi.py
My wsgi.py contents is as follows
#!/usr/bin/python
from app import app
from app import views
if __name__ == '__main__':
app.run()
Contents of init.py in app package
#!/usr/bin/python
from flask import Flask
app = Flask(__name__)
I started wsgi as below
uwsgi --socket 127.0.0.1:8080 --protocol=http -w wsgi
The server is started successfully but I can error in startup log as below
*** WARNING: you are running uWSGI without its master process manager ***
your processes number limit is 709
your memory page size is 4096 bytes
detected max file descriptor number: 256
lock engine: OSX spinlocks
thunder lock: disabled (you can enable it with --thunder-lock)
uwsgi socket 0 bound to TCP address 127.0.0.1:8080 fd 3
Python version: 2.7.6 (default, Sep 9 2014, 15:04:36) [GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)]
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0x7fd7eb6000d0
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 72760 bytes (71 KB) for 1 cores
*** Operational MODE: single process ***
unable to load app 0 (mountpoint='') (callable not found or import error)
*** no app loaded. going in full dynamic mode ***
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI worker 1 (and the only) (pid: 70195, cores: 1)
Similar issues were posted but whatever solutions offered for those issues are already in my code. I am not able to find why I am getting this error.
Thanks

"Callable not found is the issue" (not the import error, i suspect). Change:
uwsgi --socket 127.0.0.1:8080 --protocol=http -w wsgi
into this
uwsgi --socket 127.0.0.1:8080 --protocol=http -w wsgi:app
or
uwsgi --socket 127.0.0.1:8080 --protocol=http --module wsgi --callable app
see here, search for 'flask deploy'.

Related

uwsgi + django + nginx: Python application not loading

Following a bunch of tutorials, I wrote my first django app and then decided to deploy it on a linode server. Following their tutorial, I only got so far. The best I could tell, that was based on an earlier version of Ubunto and I tried some other things, including the uwsgi quickstart tutorial.
I got far enough that the command 'python manage.py runserver' would serve up my site and wanted to move on to using uwsgi to do the same.
It seems as though there is some environment variable missing. When I try to start uwsgi from the command line with:
uwsgi --http :8000 --module dynamicefl.wsgi
I get the following:
*** Starting uWSGI 2.0.15 (64bit) on [Fri Aug 11 19:37:04 2017] ***
compiled with version: 6.3.0 20170406 on 10 August 2017 23:41:13
os: Linux-4.9.36-x86_64-linode85 #1 SMP Thu Jul 6 15:31:23 UTC 2017
nodename: roosevelt
machine: x86_64
clock source: unix
detected number of CPU cores: 1
current working directory: /home/django/worksheets/dynamic-efl
detected binary path: /usr/local/bin/uwsgi
!!! no internal routing support, rebuild with pcre support !!!
*** WARNING: you are running uWSGI without its master process manager ***
your processes number limit is 3941
your memory page size is 4096 bytes
detected max file descriptor number: 1024
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
uWSGI http bound on :8000 fd 4
spawned uWSGI http 1 (pid: 5998)
uwsgi socket 0 bound to TCP address 127.0.0.1:43637 (port auto-assigned) fd 3
Python version: 2.7.13 (default, Jan 19 2017, 14:48:08) [GCC 6.3.0 20170118]
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0x562bdad6fda0
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 72760 bytes (71 KB) for 1 cores
*** Operational MODE: single process ***
Traceback (most recent call last):
File "./dynamicefl/wsgi.py", line 12, in <module>
from django.core.wsgi import get_wsgi_application
ImportError: No module named django.core.wsgi
unable to load app 0 (mountpoint='') (callable not found or import error)
*** no app loaded. going in full dynamic mode ***
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI worker 1 (and the only) (pid: 5997, cores: 1)
A lot of the tutorials emphasize putting the path to the virtual environment in the .ini file, and I did (double checking with 'env' that I had the virtual environment right.) Here is the .ini file I'm working with
[uwsgi]
home = /home/django/Env/worksheets
chdir = /home/django/worksheets/dynamic-efl/dynamicefl
module = dynamicefl.wsgi::application
uid = www-data
gid = www-data
socket = localhost:9191
chmod-socket = 644
chown-socket = www-data
processes = 4
threads = 2
logto = /var/log/uwsgi.log
I have experimented with changing the chdir command some, as I'm not sure exactly where it should be pointing, but regarless of where it points that results in a similar line in uwsgi.log:
-- no python application found, check your startup logs for errors ---
(Fun fact: I haven't been able to find reference to uwsgi startup logs)
If I go to the site in my web browser, I get an 'Internal Server Error' message.
I don't think that anything is getting as far an nginx, but I can include the .conf file and error logs, too, if that's helpful.
I know that there are a log of similar questions, but I've looked at them and they're not helping me. (Which is not to say that they don't contain the answer.)
The django docs helped me out here. It turns out that my reference to the module was apparently wrong. I had a colon too many in the reference to the module. The corrected .ini reads:
module = dynamicefl.wsgi:application
What helped was resolving to battle it out until I could serve the site purely from uwsgi, so that I could stop restarting services.

uWSGI + Django + Python: no module named uwsgi

I am trying to setup uwsgi for my Django project.
It runs fine with
./manage.py runserver 0.0.0.0:9010
But when I try
uwsgi --http :9010 --chdir /home/user/appname --module wsgi --wsgi-file /home/user/appname/appname/wsgi.py
I get
ImportError: No module named wsgi
What I am doing wrong ?
Here is the full log:
uWSGI http bound on :9010 fd 4
spawned uWSGI http 1 (pid: 1900)
uwsgi socket 0 bound to TCP address 127.0.0.1:42684 (port auto-assigned) fd 3
Python version: 2.7.9 (default, Mar 1 2015, 13:01:26) [GCC 4.9.2]
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0x1c17310
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 72760 bytes (71 KB) for 1 cores
*** Operational MODE: single process ***
ImportError: No module named wsgi
unable to load app 0 (mountpoint='') (callable not found or import error)
Traceback (most recent call last):
File "/home/robert/surmaroute/surmaroute/wsgi.py", line 13, in <module>
from django.core.wsgi import get_wsgi_application
ImportError: No module named django.core.wsgi
unable to load app 0 (mountpoint='') (callable not found or import error)
*** no app loaded. going in full dynamic mode ***
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI worker 1 (and the only) (pid: 1899, cores: 1)
The issue is that your app does not have a module named uwsgi. You change the directory to /home/user/appname but it looks like the actual module would be appname.uwsgi since the uwsgi.py file lives within /home/user/appname/appname/uwsgi.py.
Typically though, you don't need to specify both --wsgi-file and --module so I would either do
uwsgi --http :9010 --chdir /home/user/appname --wsgi-file /home/user/appname/appname/wsgi.py
or
uwsgi --http :9010 --chdir /home/user/appname --module appname.uwsgi
I personally prefer the second.

simple Bottle app with uWSGI not working (returns 404)

I have a simple hello-world app built with Bottle:
from bottle import route, run
import bottle
app = bottle.Bottle()
#route('/hello')
def hello():
return "hello world"
if __name__ == '__main__':
run(port=8080, debug=True)
else:
application = app
It works on 127.0.0.1:8080 when ran by python bottle-hello.py. But when I try to run it using uWSGI:
uwsgi --http :8000 --wsgi-file bottle-hello.py
Visiting 127.0.0.1:8000 gives a 404 not found error.
Here is the log info from uWSGI output. Last line show it receives the request but returns nothing ...
*** Starting uWSGI 2.0.4 (64bit) on [Tue May 27 15:12:52 2014] ***
compiled with version: 4.8.2 on 27 May 2014 14:05:00
os: Linux-3.13.0-27-generic #50-Ubuntu SMP Thu May 15 18:06:16 UTC 2014
nodename: ubuntu
machine: x86_64
clock source: unix
detected number of CPU cores: 1
current working directory: /apps/bottle-hello
detected binary path: /usr/local/bin/uwsgi
!!! no internal routing support, rebuild with pcre support !!!
*** WARNING: you are running uWSGI without its master process manager ***
your processes number limit is 7726
your memory page size is 4096 bytes
detected max file descriptor number: 1024
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
uWSGI http bound on :8000 fd 4
spawned uWSGI http 1 (pid: 8694)
uwsgi socket 0 bound to TCP address 127.0.0.1:48544 (port auto-assigned) fd 3
Python version: 2.7.6 (default, Mar 22 2014, 23:03:41) [GCC 4.8.2]
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0x25bb130
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 72752 bytes (71 KB) for 1 cores
*** Operational MODE: single process ***
WSGI app 0 (mountpoint='') ready in 0 seconds on interpreter 0x25bb130 pid: 8693 (default app)
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI worker 1 (and the only) (pid: 8693, cores: 1)
[pid: 8693|app: 0|req: 1/1] 127.0.0.1 () {36 vars in 632 bytes} [Tue May 27 15:13:01 2014] GET /hello => generated 730 bytes in 20 msecs (HTTP/1.1 404) 2 headers in 87 bytes (1 switches on core 0)
Here comes corrected code:
import bottle
app = application = bottle.Bottle()
#app.route('/hello')
def hello():
return "hello world"
if __name__ == '__main__':
app.run(port=8080, debug=True)

Super basic uwsgi configuration

I've tried some uwsgi tutorials but can't get a simple python script to run in my browser.
Ive read through this (http://uwsgi-docs.readthedocs.org/en/latest/WSGIquickstart.html) and this (https://www.digitalocean.com/community/articles/how-to-deploy-python-wsgi-applications-using-uwsgi-web-server-with-nginx) and others, but for some reason can't get a simple uwsgi app running. I am currently not going through a web server, just uwsgi by itself.
I have the following wsgi.py:
def application(env, start_response):
start_response('200 OK', [('Content-Type', 'text/html')])
return ["Hello!"]
and I run:
uwsgi --socket 127.0.0.1:8080 --chdir /my/program/path --pp .. -w wsgi
which produces the following output (looks promising):
*** Starting uWSGI 2.0.3 (64bit) on [Mon Apr 14 12:51:32 2014] ***
compiled with version: 4.6.3 20120306 (Red Hat 4.6.3-2) on 14 April 2014 12:01:33
os: Linux-3.1.0-7.fc16.x86_64 #1 SMP Tue Nov 1 21:10:48 UTC 2011
nodename: ip-10-252-98-215
machine: x86_64
clock source: unix
detected number of CPU cores: 1
current working directory: /usr/oai/icscada/www
detected binary path: /usr/bin/uwsgi
!!! no internal routing support, rebuild with pcre support !!!
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) ***
*** WARNING: you are running uWSGI without its master process manager ***
your processes number limit is 1024
your memory page size is 4096 bytes
detected max file descriptor number: 1024
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
uwsgi socket 0 bound to TCP address 127.0.0.1:8080 fd 3
Python version: 2.7.3 (default, Jul 24 2012, 11:41:40) [GCC 4.6.3 20120306 (Red Hat 4.6.3-2)]
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0x2504ee0
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 72752 bytes (71 KB) for 1 cores
*** Operational MODE: single process ***
added ../ to pythonpath.
WSGI app 0 (mountpoint='') ready in 0 seconds on interpreter 0x2504ee0 pid: 21702 (default app)
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI worker 1 (and the only) (pid: 21702, cores: 1)
but when I go to port 8080 from my browser I get a "could not connect" error. Port 8080 is open and has been tested.
I've also tried the following wsgi.py:
import os
os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
exactly the same results
If you want to run uWSGI without a web server in front of it, use http option instead of socket. See Native HTTP support.
Also, use 0.0.0.0:80 as an address if you are accessing from a remote machine.

Django + uwsgi + nginx . Import error: No module named py

I am trying to run my sample django application using uWSGI and nginx. But I am getting import error, no module named py. I am not sure where should I add the python path.
I am running with the following command.
sudo uwsgi --socket mysite.socket --module wsgi.py --chmod-socket=666.
I even tried passing path in the parameter --pythonpath, still the same error.
This is how my wsgi.py looks like
enter code here
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
When I try running, I get the following messages
ubuntu#ubuntu1204desktopi386:/usr/local/lib/python2.7/site-packages/mysite/mysite
$ sudo uwsgi --socket mysite.socket --module wsgi.py --chmod-socket=666
*** Starting uWSGI 1.9.18.1 (32bit) on [Mon Oct 14 13:15:19 2013] ***
compiled with version: 4.6.3 on 13 October 2013 02:53:51
os: Linux-3.5.0-23-generic #35~precise1-Ubuntu SMP Fri Jan 25 17:15:33 UTC 2013
nodename: ubuntu1204desktopi386
machine: i686
clock source: unix
pcre jit disabled
detected number of CPU cores: 1
current working directory: /usr/local/lib/python2.7/site-packages/mysite/mysite
detected binary path: /usr/local/bin/uwsgi
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) ***
*** WARNING: you are running uWSGI without its master process manager ***
your processes number limit is 3846
your memory page size is 4096 bytes
detected max file descriptor number: 1024
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
uwsgi socket 0 bound to UNIX address mysite.socket fd 3
Python version: 2.7.3 (default, Sep 26 2013, 20:26:19) [GCC 4.6.3]
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0x9644d68
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 64024 bytes (62 KB) for 1 cores
*** Operational MODE: single process ***
ImportError: No module named py
unable to load app 0 (mountpoint='') (callable not found or import error)
*** no app loaded. going in full dynamic mode ***
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI worker 1 (and the only) (pid: 2311, cores: 1)
The --module argument is presumably meant to be a Python module, not a file. So you probably just need --module=wsgi.
i guess you can also use , --wsgi-file wsgi.py like this
$ uwsgi --socket 127.0.0.1:8000 --wsgi-file my_proj/wsgi.py
Make sure you run command from same folder
If python manage.py runserver 0.0.0.0:8024 can work well, then
This also can work(run it on the same directory as above command):
uwsgi --http :8024 --module mysite.wsgi
mysite is the name of this django project
uwsgi version is 2.0.14;
django version is 1.10.
ref: https://uwsgi-docs.readthedocs.io/en/latest/tutorials/Django_and_nginx.html

Categories