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

94 Views Asked by At

I have a python script with flask API. I am running the code in command line python scriptname.py and making an POST call and it works.

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. 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)
1

There are 1 best solutions below

1
Divyani Singh On

You either need to deploy the flask backend on server or on windows you can use "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/