赞
踩
碰到这个问题,请留意下系统执行的python版本和自己的django版本
可以使用
uwsgi --python -version
也可以查看 运行之后的脚本提示信息
一般都是多版本兼容问题
uwsgi --python -version
uwsgi --python-version
按照文档,首先写一个test.py的文件,进行测试是否安装成功
def application(env, start_response):
start_response('200 OK', [('Content-Type','text/html')])
return [b"Hello World"] # python3
结果页面显示
Internal Server Error
控制台显示
no python application found, check your startup logs for errors
重新查看手册,发现,需要在命令行添加参数 --plugin python
执行下面命令行:
uwsgi --plugin python --http :8001 --wsgi-file test.py
重新访问 localhost:8001
就可以看到 成功的显示了 ‘Hello world’
PS:附件为uwsgi的手册
https://media.readthedocs.org/pdf/uwsgi-docs-additions/latest/uwsgi-docs-additions.pdf
起初没400 Bad request
过一段时间就产生了
[pid: 14558|app: 0|req: 23/23] 123.127.3.37 () {38 vars in 653 bytes} [Mon Aug 4 21:29:55 2014] GET / => generated 0 bytes in 6 msecs (HTTP/1.1 500) 4 headers in 147 bytes (1 switches on core 0)
[pid: 14558|app: 0|req: 24/24] 123.127.3.37 () {38 vars in 651 bytes} [Mon Aug 4 21:30:01 2014] GET / => generated 26 bytes in 2 msecs (HTTP/1.1 400) 1 headers in 53 bytes (1 switches on core 0)
SIGPIPE: writing to a closed pipe/socket/fd (probably the client disconnected) on request / (ip 123.127.3.37) !!!
Mon Aug 4 21:30:40 2014 - write(): Broken pipe [proto/uwsgi.c line 138] during GET / (123.127.3.37)
[pid: 14558|app: 0|req: 25/25] 123.127.3.37 () {38 vars in 653 bytes} [Mon Aug 4 21:30:40 2014] GET / => generated 0 bytes in 6 msecs (HTTP/1.1 500) 4 headers in 147 bytes (1 switches on core 0)
SIGPIPE: writing to a closed pipe/socket/fd (probably the client disconnected) on request /robots.txt (ip 66.249.73.168) !!!
Mon Aug 4 21:56:36 2014 - write(): Broken pipe [proto/uwsgi.c line 138] during GET /robots.txt (66.249.73.168)
[pid: 14558|app: 0|req: 26/26] 66.249.73.168 () {40 vars in 573 bytes} [Mon Aug 4 21:56:36 2014] GET /robots.txt => generated 0 bytes in 4 msecs (HTTP/1.1 404) 4 headers in 135 bytes (1 switches on core 0)
[pid: 14558|app: 0|req: 27/27] 222.218.51.29 () {28 vars in 307 bytes} [Mon Aug 4 22:01:48 2014] GET / => generated 26 bytes in 2 msecs (HTTP/1.0 400) 1 headers in 53 bytes (1 switches on core 0)
[pid: 14558|app: 0|req: 28/28] 182.136.237.186 () {28 vars in 309 bytes} [Mon Aug 4 22:03:09 2014] GET / => generated 26 bytes in 2 msecs (HTTP/1.0 400) 1 headers in 53 bytes (1 switches on core 0)
root@AY140715013539708c0eZ:/var/log# ^C
root@AY140715013539708c0eZ:/var/log# ls -l uwsgi.log
-rw-r----- 1 root root 8694 Aug 4 22:05 uwsgi.log
root@AY140715013539708c0eZ:/var/log# vi uwsgi.log
[pid: 14558|app: 0|req: 29/29] 123.127.3.37 () {38 vars in 653 bytes} [Mon Aug 4 22:05:06 2014] GET / => generated 0 bytes in 6 msecs (HTTP/1.1 500) 4 headers in 147 bytes (1 switches on core 0)
[pid: 14558|app: 0|req: 30/30] 123.127.3.37 () {38 vars in 651 bytes} [Mon Aug 4 22:05:13 2014] GET / => generated 26 bytes in 2 msecs (HTTP/1.1 400) 1 headers in 53 bytes (1 switches on core 0)
毫无疑问,又是能让我跳楼的BUG,但是结果都一样,很小的细节,卡我两天时间。
在ubuntu上部署django项目时,需要安装uwsgi服务器。根据教程安装完之后,然后会有一个小测试,就是写一个test.py文件运行一下看uwsgi是否安装成功。具体的test.py文件我就不贴了,网上一堆。
然后重要的是在运行命令:uwsgi –http :8001 –wsgi-file test.py时,报错了。详细错误信息如下:
dh@ubuntu:~$ uwsgi –http :8001 –wsgi-file test.py
Starting uWSGI 2.0.17 (64bit) on [Mon Jun 11 12:37:29 2018]
compiled with version: 7.3.0 on 07 June 2018 06:45:48
os: Linux-4.15.0-22-generic #24-Ubuntu SMP Wed May 16 12:15:17 UTC 2018
nodename: ubuntu
machine: x86_64
clock source: unix
detected number of CPU cores: 4
current working directory: /home/dh
detected binary path: /home/dh/.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 15072
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 :8001 fd 4
spawned uWSGI http 1 (pid: 18207)
uwsgi socket 0 bound to TCP address 127.0.0.1:36073 (port auto-assigned) fd 3
Python version: 3.6.5 (default, Apr 1 2018, 05:46:30) [GCC 7.3.0]
Python threads support is disabled. You can enable it with –enable-threads
Python main interpreter initialized at 0x55e5bf3e29c0
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 72904 bytes (71 KB) for 1 cores
Operational MODE: single process
failed to open python file test.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: 18206, cores: 1)
报错的就是最后那三句:
failed to open python file test.py
unable to load app 0 (mountpoint=”) (callable not found or import error)
no app loaded. going in full dynamic mode
找不到test.py文件
在根据教程安装uwsgi时,我的理解是,安装完 ,直接在django项目里写一个test.py文件,再用命令运行就可以。
实际的步骤是:安装完uwsgi后,在任何位置都可以写这个test.py文件,然后打开终端运行命令时的位置必须和这个test.py文件位置相同,例如:test.py文件的路径是/home/etc/test.py,那你终端的位置也应该是/home/etc/test.py,就不会报这个错了。
最后再列一下安装uwsgi的正确步骤:
1.sudo apt-get install libpcre3 libpcre3-dev
,第一步必须先安装这个库文件,不然不报错:no internal routing support, rebuild with pcre support
2.sudo pip3 install uwsgi
,这里和上一篇注意的BUG一样,如果你是python3,就一定要用pip3安装
3.任何位置写一个test.py,内容如下
def application(env, start_response):
start_response(‘200 OK‘, [(‘Content-Type‘,‘text/html‘)])
return [b”Hello World”]
4.然后启动终端,和之前说的一样,终端的位置要和test的文件位置相同,运行命令:uwsgi –http :8001 –wsgi-file test.py
5.浏览器里输入:127.0.0.1:8001就可以看到输出效果:Hello World
OK了
— no python application found, check your startup logs for errors
uwsgi:no python application found, check your startup logs for errors错误的解决
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。