【问题标题】:Python webapp not running properly on Heroku?Python webapp 在 Heroku 上无法正常运行?
【发布时间】:2018-10-28 11:36:36
【问题描述】:

我尝试在 Heroku 上部署 this application。当我在笔记本电脑上本地启动它时,它运行正常,但在 Heroku 上部署它以查看结果后,我遇到了一些问题:我可以在线看到应用程序的整个前端,但随机数没有动态显示在网页上。

我不知道如何调试它,因为在我的 Heroku 控制台上没有出现任何错误,所以我根本没有收到任何错误。有什么建议吗?

我的 procfile 如下所示:

web: gunicorn --worker-class eventlet -w 1 orig:app

编辑 1: 我打开我的谷歌浏览器控制台发现了这个:

Mixed Content: The page at 'https://fast-everglades-74376.herokuapp.com/' was loaded over HTTPS, but attempted to connect to the insecure WebSocket endpoint 'ws://fast-everglades-74376.herokuapp.com/socket.io/?EIO=3&transport=websocket&sid=2e9895ef6415455eac51294746b3edf6'. This endpoint should be available via WSS. Insecure access is deprecated.

socket.io.min.js:1 POST http://fast-everglades-74376.herokuapp.com/socket.io/?EIO=3&transport=polling&t=1540729336006-41&sid=f550b39a0e1e4544b1eee0c3f1719871 400 (BAD REQUEST)

另外,在 Firefox 控制台上,我收到另一个关于混合活动内容的错误

编辑 2: 我将 Gunicorn 模块的版本从 19.3 更改为 18.0,之后我尝试在 http 而不是 https 上运行页面。在http上它似乎可以运行,问题是它现在不会在https上运行。

【问题讨论】:

    标签: python heroku websocket socket.io


    【解决方案1】:

    关于部署到heroku,您需要安装eventlet 才能运行socket-io 应用程序。另外,您需要Procfile。它基本上告诉 heroku “应用程序”如何运行。在我的示例here 中,只需输入一行:

    web: gunicorn -k eventlet python_file:flask_variable_name
    

    在你的例子中,我认为

    web: gunicorn -k eventlet application:app
    

    另外,在部署时,请务必从 heroku 仪表板中添加 Procfile 并将其设置为 "On"

    【讨论】:

    • 嘿,我编辑了问题并添加了 procfile!来看看吧!
    • 所以我编辑了我的 procfile 并使用了你给我的那个,但它还没有工作,同样的问题。会不会是 flask_variable_name 部分?
    • 我创建了一个 requirements.txt 文件和 procfile,使用了 git init 和 git add .,使用 git commit 提交了应用程序,然后推送了所有内容。结果如下:fast-everglades-74376.herokuapp.com,您可以看到整个前端部分都在那里,但我缺少数字
    • 是的,每次我编辑某些内容时,我都会提交我的本地更改并再次推送所有内容。关于 Procfile,当我转到概述时,我可以看到在“web”附近启用了 procfile
    • 请不要添加无关紧要的内容,例如“哦,嗨。又是我,回答了之前的烧瓶套接字问题。”问题和答案应侧重于相关信息。
    猜你喜欢
    • 2011-07-14
    • 2017-09-05
    • 2020-09-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-08
    • 1970-01-01
    相关资源
    最近更新 更多