Deploy Aiohttp On Heroku
I have built a simple web server on aiohttp and try to deploy it on heroku, but after deployment I get an error message: at=error code=H14 desc='No web processes running' dyno= c
Solution 1:
Probably aiohttp isn't listening on the right port. You need something like web.run_app(app, port=os.getenv('PORT'))
.
Update: wait, you're trying to serve it both with gunicorn and with web.run_app
which is wrong, you'll need to either just have something like web: python application.py
or remove the web.run_app(app)
.
Solution 2:
If you have an app in myapp.py
like so,
import os
from aiohttp import web
#...define routes...async def create_app():
app = web.Application()
app.add_routes(routes)
return app
# If running directly https://docs.aiohttp.org/en/stable/web_quickstart.htmlif __name__ == "__main__":
port = int(os.environ.get('PORT', 8000))
web.run_app(create_app(), port=port)
You can run it both locally via the python
CLI but also as a worker process managed by gunicorn
with a Procfile
similar to this:
# use if you wish to run your server directly instead of via an application runner#web: python myapp.py# see https://docs.aiohttp.org/en/stable/deployment.html#nginx-gunicorn# https://devcenter.heroku.om/articles/python-gunicorn# http://docs.gunicorn.org/en/latest/run.html
web: gunicorn --bind 0.0.0.0:$PORT -k aiohttp.worker.GunicornWebWorker myapp:create_app
Post a Comment for "Deploy Aiohttp On Heroku"