Search code examples
python-3.xerror-handlingtornado

Exception has occurred: NotImplementedError


Executed this for the first time and getting exception at app.listen(port)

import tornado.web
import tornado.ioloop

class basicRequestHandler(tornado.web.RequestHandler):
    def get(self):
        self.write("Hello, World this is a python command executed from the  backend.")

if __name__ == "__main__":
    app = tornado.web.Application([
        (r"/", basicRequestHandler)
    ])

    port = 8882
    app.listen(port)#Getting exception here 
    print(f"Application is ready and listening on port {port}")
    tornado.ioloop.IOLoop.current().start()

Solution

  • in python 3.8:

    import tornado.ioloop
    import tornado.web
    import asyncio
    
    class basicRequestHandler(tornado.web.RequestHandler):
        def get(self):
            self.write("Hello, World this is a python command executed from the  backend.")
    
    if __name__ == "__main__":
        asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
        app = tornado.web.Application([
        (r"/", basicRequestHandler)
        ])
        port = 8882
        app.listen(port)
        print(f"Application is ready and listening on port {port}")
        tornado.ioloop.IOLoop.current().start()