【问题标题】:Deploy aiohttp web server on heroku在heroku上部署aiohttp web服务器
【发布时间】:2020-12-21 13:20:04
【问题描述】:

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

它在 localhost 中运行良好,但是当我将它上传到 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 的问题也没有帮助。

【问题讨论】:

    标签: python heroku aiohttp


    【解决方案1】:

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

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

    代替

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

    【讨论】:

      猜你喜欢
      • 2018-12-28
      • 2018-06-13
      • 2017-04-22
      • 2018-04-18
      • 2016-08-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多