解決思路:no python application found, check your startup logs for errors

uwsgi部署python web項目的時候可能會出現標題報錯:

解決思路,看日誌:

[root@lovecat uswgi]# uwsgi --http :9090 --wsgi-file /app/uwsgi/start:app
*** Starting uWSGI 2.0.18 (64bit) on [Thu Oct 10 02:28:27 2019] ***
compiled with version: 4.8.5 20150623 (Red Hat 4.8.5-36) on 23 September 2019 03:04:11
os: Linux-3.10.0-693.el7.x86_64 #1 SMP Tue Aug 22 21:09:27 UTC 2017
nodename: lovecat.liu.com
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 4
current working directory: /app/uswgi
detected binary path: /usr/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 15086
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 :9090 fd 4
spawned uWSGI http 1 (pid: 30841)
uwsgi socket 0 bound to TCP address 127.0.0.1:40858 (port auto-assigned) fd 3
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) *** 
Python version: 2.7.5 (default, Aug  7 2019, 00:51:29)  [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)]
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0x19d4940
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) *** 
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 72920 bytes (71 KB) for 1 cores
*** Operational MODE: single process ***
failed to open python file /app/uwsgi/start:app
unable to load app 0 (mountpoint='') (callable not found or import error)
*** no app loaded. going in full dynamic mode ***
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) *** 
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI worker 1 (and the only) (pid: 30840, cores: 1)
--- no python application found, check your startup logs for errors ---
[pid: 30840|app: -1|req: -1/1] 116.228.50.38 () {40 vars in 701 bytes} [Thu Oct 10 02:28:31 2019] GET / => generated 21 bytes in 0 msecs (HTTP/1.1 500) 2 headers in 83 bytes (0 switches on core 0)
--- no python application found, check your startup logs for errors ---

 以上是啓動一次uwsgi彈出的信息,不要只是等着web請求看請求信息,啓動的這麼多內容中,包含很多關鍵信息,包括絕大多數人會忽略的啓動失敗信息,uwsgi啓動錯誤並不會停止進程,而是會把相關錯誤直接在啓動log中直接打出

上圖中就有啓動錯誤信息:

failed to open python file /app/uwsgi/start:app
unable to load app 0 (mountpoint='') (callable not found or import error)

這代表沒有打開文件,文件內容不正確導致無法加載。

 

uwsgi啓動錯誤可能有很多種,不是所有的報錯我都遇到了,但是錯誤信息都會在log中打出,然後根據錯誤信息去解決就好了;

本次我遇到的錯誤是:

centos7 中python2 版本和python3版本共存,即使pip3 install 的uwsgi直接啓動也會調用python2,如上圖調用的版本信息;

解決思路,直接找到pip3安裝的uwsgi,把這個啓動文件軟鏈導/usr/bin目錄下,替換調調用2的啓動軟鏈文件即可,如果無法替換,可以改個名字,比如uwsgi3,以後啓動uwsgi的時候以uwsgi3 --http :9090 -w rest.py這種形式啓動即可;

有的報錯會是模塊內app啓動寫法不對,根據相關報錯找到對應解決方法即可;

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章