python - 运行 streamline 作为前端和 FastAPI 作为后端时出错

我开发了一个机器学习应用程序,以 fastapi 作为后端,streamlit 作为前端,当我运行它时它可以在我的本地机器上运行,我很可能使用在 后端。但是使用 docker ,它们单独工作,我可以使用快速 API 生成预测,并且可以使用 streamlit 查看 UI,但是如果我想在 streamlit UI 上生成预测,它会生成此错误:

ConnectionError: HTTPConnectionPool(host='localhost', port=8000): Max retries exceeded with URL: /predict (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0xffffa808a0d0>: Failed to establish a new connection: [Errno 111] Connection refused'))

错误可能来自哪里?

回答1

我有同样的问题。

FastAPI API 在 8108 公开,所以从 streamlit 前面我使用过:

response = requests.post('http://localhost:8108/predict', json=msg)

或者

response = requests.post('http://0.0.0.0:8108/predict', json=msg)

或者

response = requests.post('http://127.0.0.0:8108/predict', json=msg)

每次尝试都失败了。总是同样的错误

ConnectionError: HTTPConnectionPool(host='0.0.0.0', port=8108): Max retries exceeded with url: /predict (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fd5b257d240>: Failed to establish a new connection: [Errno 111] Connection refused'))

相似文章

随机推荐

最新文章