• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • YouClaw
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录

无信不立

  • 博客园
  • 联系
  • 订阅
  • 管理

公告

View Post

【python】uwsgi项目第一个个人小程序说明 和 Liunx上安装uwsgi

一、安装uwsgi服务器

wget http://projects.unbit.it/downloads/uwsgi-latest.tar.gz
tar zxvf uwsgi-latest.tar.gz
cd <dir>
make
View Code

二、编写处理请求的python脚本

WSGIWebReqHandler.py

#env : 包含了http请求所有内容的字典
#start_response: 一个响应http请求的函数
def application(env, start_response):
    print("print env content="+str(env))
    request_body_size = int(env.get('CONTENT_LENGTH', 0))
    print("*************[reqBodySize:]"+str(request_body_size))
    raw_request_body = env['wsgi.input'].read(request_body_size)
    raw_request_body_decoded = raw_request_body.decode('utf-8')
    print("*************[reqBodyContent:]"+str(raw_request_body_decoded))
    start_response('200 OK', [('Content-Type','text/html')])
    return [b"Hello World_sxf"]

三、编写处理请求的python脚本

3、启动项目进程

uwsgi --http :9090 --wsgi-file WSGIWebReqHandler.py

4、使用postMan发送请求

5、后端打印的日志信息如下:

print env content={
    'REQUEST_METHOD': 'POST',
    'PATH_INFO': '/testName/pay',
    'REQUEST_URI': '/testName/pay?token_sxf=123&token_name=%22%E4%B8%8A%E5%B2%97%22',
    'QUERY_STRING': 'token_sxf=123&token_name=%22%E4%B8%8A%E5%B2%97%22',
    'SERVER_PROTOCOL': 'HTTP/1.1',
    'SCRIPT_NAME': '',
    'SERVER_NAME': 'XXSHANG-MC0',
    'SERVER_PORT': '9090',
    'UWSGI_ROUTER': 'http',
    'REMOTE_ADDR': '127.0.0.1',
    'REMOTE_PORT': '40933',
    'HTTP_ACCEPT': '*/*',
    'HTTP_ACCEPT_ENCODING': 'gzip, deflate, br',
    'HTTP_USER_AGENT': 'PostmanRuntime-ApipostRuntime/1.1.0',
    'HTTP_CONNECTION': 'keep-alive',
    'CONTENT_TYPE': 'application/json',
    'HTTP_CACHE_CONTROL': 'no-cache',
    'HTTP_HOST': 'localhost:9090',
    'CONTENT_LENGTH': '50',
    'wsgi.input': < uwsgi._Input object at 0x10422b590 > ,
    'wsgi.file_wrapper': < built - in function uwsgi_sendfile > ,
    'wsgi.version': (1, 0),
    'wsgi.errors': < _io.TextIOWrapper name = 2 mode = 'w'
    encoding = 'UTF-8' > ,
    'wsgi.run_once': False,
    'wsgi.multithread': False,
    'wsgi.multiprocess': False,
    'wsgi.url_scheme': 'http',
    'uwsgi.version': b '2.0.28',
    'uwsgi.node': b 'XXSHANG-MC0'
}
*************[reqBodySize:]50
*************[reqBodyContent:]{
"username":"尚晓飞12343",
"userpwd":"1243"

}

 

 

 

 

四、 Liunx上安装uwsgi

4.1、下载uwsgi的安装包

wget http://projects.unbit.it/downloads/uwsgi-latest.tar.gz

下载下来安装包:uwsgi-latest.tar.gz

 

4.2、解压并编译

tar -xzvf uwsgi-latest.tar.gz
cd uwsgi-2.0.20
make

4.3、报错

In file included from plugins/python/python_plugin.c:1:
plugins/python/uwsgi_python.h:2:10: fatal error: Python.h: No such file or directory
 #include <Python.h>
          ^~~~~~~~~~
compilation terminated.
make: *** [Makefile:4: all] Error 1
[xxshang@VM-212-227-tencentos uwsgi-2.0.20]$ In file included from plugins/python/pyutils.c:1:
plugins/python/uwsgi_python.h:2:10: fatal error: Python.h: No such file or directory
 #include <Python.h>
          ^~~~~~~~~~
compilation terminated.
In file included from plugins/python/pyloader.c:1:
plugins/python/uwsgi_python.h:2:10: fatal error: Python.h: No such file or directory
 #include <Python.h>
          ^~~~~~~~~~

4.4、排查到原因是因为少xx环境,所以需要安装

这个错误信息表明在编译 uwsgi 时,编译器找不到 Python.h 头文件。Python.h 是 Python 的 C API 头文件,通常在安装 Python 开发包(Python Development Kit, PDK)时会包含这个文件。

sudo yum install python3-devel
View Code

 

4.5、再次执行make,则生成uwsgi的二进制文件

 

posted on 2024-11-17 16:30  无信不立  阅读(33)  评论(0)    收藏  举报

刷新页面返回顶部
 
博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3