我开发了一个机器学习应用程序,以 fastapi 作为后端,streamlit 作为前端,当我运行它时它可以在我的本地机器上运行,我很可能使用在
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'))