无法联系“工人”来自 Web 进程的 Heroku 进程:`ConnectionRefusedError`
我有一个 web
进程和一个 api
进程(一个类似于 文档 和 这些其他文档)。但是,我不明白不同进程之间的网络是如何工作的。
两个进程都在侦听 0.0.0.0
,并且工作进程绑定到端口 5000。但是,当我尝试从 web
进程发出请求时,我得到一个ConnectionRefusedError
:
ConnectionError: HTTPConnectionPool(host='0.0.0.0', port=5000): Max retries exceeded with url: /tokenize?sentence=hello (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fd307019dc0>: Failed to establish a new connection: [Errno 111] Connection refused'))
我应该找出其他进程的IP吗?我在这里做错了什么吗?
Procfile:
api: python app.py
web: voila UI.ipynb --port $PORT --Voila.ip=0.0.0.0
app.py:
from flask import Flask, request
from ie_utils import tokenize
app = Flask(__name__)
@app.route("/")
def home():
return {
"message": "Hello world!",
"version": "0.1",
}
if __name__ == "__main__":
import os
port = 5000
app.run(host="0.0.0.0", port=port)
UI.ipynb
中的相关代码:
import requests
requests.get("http://0.0.0.0:5000/")
完整源代码:https://github.com/astrojuanlu/ie-titanic-utils-a/tree/test-procfile
I have a web
process and an api
process (a "worker" process similar to what is described in the docs and these other docs). However, I don't understand how the networking between different processes works.
Both processes are listening on 0.0.0.0
, and the worker process is bound to port 5000. However, when I try to make a request from the web
process, I get a ConnectionRefusedError
:
ConnectionError: HTTPConnectionPool(host='0.0.0.0', port=5000): Max retries exceeded with url: /tokenize?sentence=hello (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fd307019dc0>: Failed to establish a new connection: [Errno 111] Connection refused'))
Am I supposed to figure out the IP of the other process? Am I doing something wrong here?
Procfile:
api: python app.py
web: voila UI.ipynb --port $PORT --Voila.ip=0.0.0.0
app.py:
from flask import Flask, request
from ie_utils import tokenize
app = Flask(__name__)
@app.route("/")
def home():
return {
"message": "Hello world!",
"version": "0.1",
}
if __name__ == "__main__":
import os
port = 5000
app.run(host="0.0.0.0", port=port)
Relevant code in UI.ipynb
:
import requests
requests.get("http://0.0.0.0:5000/")
Full source code: https://github.com/astrojuanlu/ie-titanic-utils-a/tree/test-procfile
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
除非您使用 私人空间 (部分Heroku 的企业产品),事实并非如此:
我不完全清楚你想在这里做什么,但你无法通过向本地主机发出 HTTP 请求来做到这一点。您可能会更幸运地将其作为两个单独的应用程序运行 - 在这种情况下,您的 API 可能是它自己的
web
进程,并且您的 Voilà 应用程序可以向 API 应用程序的主机名发出请求。旁注:即使在允许这样做的系统上,您的请求也不应该发送至
0.0.0.0
。那不是真实的 IP 地址。告诉 Flask 绑定到
0.0.0.0
实际上意味着它应该监听所有可用的 IP 地址。当您想要发出请求时,您应该使用系统正在使用的真实主机名或 IP 地址之一,例如localhost
或127.0.0.1
或其公共 IP 之一地址或主机名。Unless you are using Private Spaces (part of Heroku's enterprise offering), it doesn't:
I'm not totally clear what you're trying to do here, but you won't be able to do it by making an HTTP request to localhost. You might have better luck running this as two separate apps—in that case your API could be its own
web
process and your Voilà app could make requests to the API app's hostname.Side note: even on a system where this is permitted your request should not go to
0.0.0.0
. That isn't a real IP address.Telling Flask to bind to
0.0.0.0
really means that it should listen on all available IP addresses. When you want to make a request you should use one of the real hostnames or IP addresses that your system is using, e.g.localhost
or127.0.0.1
or one of its public IP addresses or hostnames.