Search code examples
pythonherokutornadoheroku-cli

Hosting Tornado server on Heroku


So I'm trying to host a python server on Heroku and I wasn't able to get it working, I have scaled to a basic hello world server for now just to get the errors out the way.

Initially, I was getting the error that Heroku could not allocate its own buildpack, so I manually added the python one, now the error is the python buildpack is not compatible with my app. Even though others have tornado working and it is pip installable

error

I have a basic directory with the only 1 python file (.git folder hidden) enter image description here

Here is the code for the server:

import tornado.ioloop
import tornado.web
import os
port = int(os.getenv('PORT', 8080))

class MainHandler(tornado.web.RequestHandler):
    def get(self):
        self.write("Hello, world")

def make_app():
    return tornado.web.Application([
        (r"/", MainHandler),
    ])

if __name__ == "__main__":
    app = make_app()
    app.listen(port)
    tornado.ioloop.IOLoop.current().start()

Any further clarifications/questions please let me know :) thanks


Solution

  • Figured out the problem, thought i'd leave it here for anyone else in the future

    You need a "Procfile" and a "requirements.txt" for heroku to know what its running and what is needed to be installed.

    enter image description here

    Procfile:

    web: python app.py
    

    requirements.txt:

    tornado==6.1