在heroku上部署aiohttp web服务器

时间:2020-12-21 13:20:04

标签: python heroku aiohttp

我正在尝试将一个非常简单的 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

此外,this 问题也没有帮助。

1 个答案:

答案 0 :(得分:0)

一行应该在这里有所帮助,试试吧:

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

代替

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