python bottle实现web服务

server:

当调用http://xxx.xxx.xxx.xxx:4500/push时就会触发get_push函数

from bottle import run, route, request
import logging
import time
import os

filename = str(os.path.basename(__file__).split('.')[0]) + ".log"
logger = logging.getLogger()
logger.setLevel(logging.INFO)
push_log = logging.FileHandler(filename, 'a', encoding='utf-8')
push_log.setLevel(logging.INFO)
# formatter = logging.Formatter("%(asctime)s - %(levelname)s - %(message)s")
# push_log.setFormatter(formatter)
logger.addHandler(push_log)


@route('/push', method=['GET', 'POST'])
def get_push():
    logging.info("---------接收数据时间" + str(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())) + "---------")
    body = request.body.decode()
    logging.info(body)

    return "200"


if __name__ == '__main__':
    run(host="xxx.xxx.xxx.xxx", port=4500, debug=True)

 

posted @ 2023-02-09 19:54  **绵绵羊**  阅读(20)  评论(0编辑  收藏  举报