I am just getting started with API's and tornado. After adding a second class to my code and running it again, I continue to get this error in the console:
[Errno 48] Address already in use
And when trying to access my second url I get this error:
tornado.web.HTTPError: HTTP 404: Not Found
This is how my code looks:
from tornado.web import Application, RequestHandler
from tornado.ioloop import IOLoop
items=[]
class TodoItems(RequestHandler):
def get(self):
self.write({'items': items})
class TodoItem(RequestHandler):
def post(self):
items.append(self.request.body)
self.write({'message': self.request.body})
def make_app():
urls = ([("/", TodoItems),
("/api/item/", TodoItem)])
return Application(urls, debug=True)
if __name__ == '__main__':
app = make_app()
app.listen(3000)
IOLoop.current().start()
What could be the problem?
I believe the fact is that you first run your program with only the first route and then you add the second one. And want to run the program again but forget to terminate the first one. So you get [Errno 48] Address already in use
because the first one is using this address. That's also why you get tornado.web.HTTPError: HTTP 404: Not Found
because you are running the old version.