Heroku:在部署应用程序时获取localhost net :: ERR_CONNECTION_REFUSED

问题描述 投票:1回答:1

我正在运行一个有两个线程的app.py,一个用于dash应用程序,另一个用于HTTPServer

app = dash.Dash(__name__)
app.layout = html.Div( ... )
@app.callback( ... )
def do_something( ... ): ...

if __name__ == '__main__':
    httpd = HTTPServer(('localhost', 8000), SimpleHTTPRequestHandler)
    t1 = threading.Thread(target=httpd.serve_forever)
    t2 = threading.Thread(target=app.run_server, kwargs={'debug': False})
    t1.start()
    t2.start()

运行HTTPServer的原因是使用url 'localhost:8000/audios/%s.wav' % clicked_index检索本地文件,并使用url作为srchtml.Audio。特别是,我在本地.wavaudios/文件,callback启用悬停并触发音频播放。

它在python app.py本地运行没有问题,但它不在已部署的应用程序上 - 悬停只触发部分音频。在屏幕截图中,带有悬停信息Piano的数据点正确播放音频,但我们可以看到ERR_CONNECTION_REFUSED在右下角的其他'localhost:8000/audios/%s.wav' % clicked_index不播放音频。这不会发生在本地。

当我用heroku run bash --app myapp检查文件时,所有的wav文件都在audios/中。

如果我在本地运行python -m http.server 8000,部署的应用程序运行没有问题;没有丢失音频播放。

我很感激任何在我刚刚开始的这个课程中启发我的人。

enter image description here

multithreading heroku flask httpserver plotly-dash
1个回答
0
投票

根据https://devcenter.heroku.com/articles/s3的说法,Heroku似乎无法托管静态文件,而s3公共存储桶满足了我的需求。

© www.soinside.com 2019 - 2024. All rights reserved.