在 heroku 上部署 aiohttp 网络服务器

Deploy aiohttp web server on heroku

我正在尝试将一个非常简单的 aiohttp 应用程序部署到 heroku,这里是 main.py 文件:

import os
from aiohttp import web

routes = web.RouteTableDef()

@routes.get('/')
async def handle(request):
    return web.Response(text='Welcome')


app = web.Application()
app.add_routes(routes)

if __name__ == '__main__':
    port = int(os.environ['PORT'])
    web.run_app(app, port=port)

这是 Procfile

web: python main.py

它在本地主机上运行良好,但是当我将它上传到 heroku 时,我得到:

 heroku[router]: at=error code=H14 desc="No web processes running" method=GET path="/favicon.ico" host=******.herokuapp.com request_id=4e96418b-04bc-4bbb-bd4f-2b17320c3bc7 fwd="81.61.104.12" dyno= connect= service= status=503 bytes= protocol=https

此外, 问题没有帮助。

一行应该对这里有所帮助,只需尝试:

web.run_app(app, port=os.getenv('PORT'))

而不是

if __name__ == '__main__':
    port = int(os.environ['PORT'])
    web.run_app(app, port=port)