0

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)
goe
  • 337
  • 2
  • 14

1 Answers1

1

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/

Divyani Singh
  • 491
  • 8
  • 16
  • I used AlwaysUp to convert the python script as windows service.Which works. But is there is any way to leverage Windows IIS – goe Aug 05 '20 at 12:10