• Python Flask+Windows Service制作


    #安装pywin32
    pip install pywin32

    #安装服务
    > python WinPyServiceExample.py install
    Installing service WinPyServiceExample
    Service installed

    #更新服务
    > python WinPyServiceExample.py update
    Changing service configuration
    Service updated

    #查看服务
    mmc Services.msc

    #停止服务
    > net stop PythonCornerExample

    #仍旧存在问题,输入下列命令调试
    python WinPyServiceExample.py debug

    #常见问题
    a. 检查Python执行路径是否在PATH变量中。可以在命令行窗口,输入python来确认。

    b. 确认 C:\Program Files\Python36\Lib\site-packages\win32\pywintypes36.dll 存在(注意: “36” 是指python安装版本)。如果这个文件不存在,从C:\Program Files\Python36\Lib\site-packages\pywin32_system32\pywintypes36.dll 拷贝到上述目录下。
    WinPyServiceExample.py
    """ 
    PythonCornerExample.py
    """

    import time
    import random
    from pathlib import Path
    from Winservice import Winservice
    from flask import Flask, request, json
    from gevent.pywsgi import WSGIServer
    from HttpApi import app
    import Config

    class PythonCornerExample(Winservice):
    _svc_name_ = "PyHttpService"
    _svc_display_name_ = "PythonHttp服务"
    _svc_description_ = "PythonHttp服务"

    def start(self):
    self.isrunning = True

    def stop(self):
    self.isrunning = False

    def main(self):
    #app.run(host="127.0.0.1", port=8000)
    ip= str(Config.get('http_host'))
    port = int(Config.get('http_port'))
    http_server = WSGIServer((ip, port), app)
    print("Serving HTTP on "+ip+" port "+str(port)+"...")
    http_server.serve_forever()


    if __name__ == '__main__':
    PythonCornerExample.parse_command_line()
    
    

    HttpApi.py:

    from flask import Flask, request, json
    from gevent.pywsgi import WSGIServer
    '''
    auth:***
    desc: http api接口
    date:20210202
    '''
    app = Flask(__name__)

    #根据图片url查询
    @app.route('/vin/imgurl')
    def vinCodeByImage():
    imgUrl = request.args.get("imgurl")
    if imgUrl=='' or len(imgUrl) ==0:
    return json.dumps({"error":True,"data":'',"message":'imgUrl could not be null'}, ensure_ascii=False, encoding="UTF-8")
    zpSaas=ZpSaas()
    jsonObj=zpSaas.checkVin(imgUrl)
    error=False
    mesaage=''
    if jsonObj['code']=='':
    error=True
    mesaage='未识别'
    else:
    error = False
    mesaage = '成功识别'
    return json.dumps({"error": error, "data": jsonObj, "message": mesaage}, ensure_ascii=False, encoding="UTF-8")

    原文:https://www.jianshu.com/p/13302948dbe6
  • 相关阅读:
    更新主窗口控件的内容1:子线程工作时同时更新主线程内的控件内容
    静态类和非静态类中静态变量
    js $的扩展写法
    js 获取时区
    export to excel
    使用Sqlserver事务发布实现数据同步(zhuanqian)
    json to entity in api
    automapper demo
    autoMapper的介绍
    Springboot的热部署
  • 原文地址:https://www.cnblogs.com/kobewang/p/15660643.html
Copyright © 2020-2023  润新知