简体   繁体   English

Python 脚本与 flask - 如何在 windows 服务器上启用设置

[英]Python script with flask - how to enable setup on windows server

I have a python script with flask API.我有一个 python 脚本和 flask API。 I am running the code in command line python scriptname.py and making an POST call and it works.我在命令行python scriptname.py中运行代码并进行 POST 调用,它可以工作。

But in realtime how to enable this set up on windows server, so that script is running and available anytime for third-party to make HTTP post.但如何在 windows 服务器上实时启用此设置,以便脚本运行并随时可供第三方发布 HTTP 帖子。 Any pointers please.请任何指点。

class Impersonate:
    def __init__(self,login,password):
        self.domain='<domain>'
        self.login=login
        self.password=password

    def logon(self):
        self.handel=win32security.LogonUser(self.login,self.domain,self.password,win32con.LOGON32_LOGON_INTERACTIVE,win32con.LOGON32_PROVIDER_DEFAULT)
        win32security.ImpersonateLoggedOnUser(self.handel)
    def logoff(self):
        win32security.RevertToSelf() #terminates impersonation
        self.handel.Close() #guarantees cleanup



a=Impersonate('testuser','password]')

try:
    a.logon() #become the user
    print(a.login)
    a.logoff() #return to normal
except:
    pass
    
    
app = Flask(__name__)
api = Api(app)


class Hellow(Resource):
    def post(self):
        path = os.path.join(parentdir, dirname)
        try:
           os.makedirs(path)
           resp = Response('{} successfully created.)
        
        
api.add_resource(Hellow, '/test')


if __name__ == "__main__":

    app.run(port=5000, host="<hostname>" use_reloader=True)

You either need to deploy the flask backend on server or on windows you can use "start /b python xyz.py".您需要在服务器或 windows 上部署 flask 后端,您可以使用“start /b python xyz.py”。 Or can also have a look at https://www.howtogeek.com/50786/using-srvstart-to-run-any-application-as-a-windows-service/或者也可以看看https://www.howtogeek.com/50786/using-srvstart-to-run-any-application-as-a-windows-service/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM