"Connection refused" 使用本地域名的烧瓶
"Connection refused" with flask using local domain name
我在我的 Raspi 上的守护进程中安装了烧瓶 运行ning。
@app.route("/cmd",methods = ['POST', 'GET'])
def cmd():
if request.method == 'GET':
order_obj = request.args.to_dict(flat=True)
else:
order_obj = request.get_json(force=True)
response = jsonify(controller_obj.act_on_order(order_obj))
response.headers.add('Access-Control-Allow-Origin', '*')
return response
app.run(port=8087, debug=config.DEBUG, use_reloader=False)
当我 运行 这个应用程序时,我可以看到它正在侦听端口 8087:
pi@brs-tv:~/brs $ sudo netstat -lptu
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 localhost:8087 0.0.0.0:* LISTEN 4133/python
当我使用本地主机远程登录到本地端口时,它工作正常。
pi@brs-tv:~/brs $ telnet localhost 8087
Trying ::1...
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
GET /cmd
但是当我本地 telnet 到它的本地地址时,我得到连接被拒绝:
pi@brs-tv:~/brs $ telnet brs-tv.local 8087
Trying 127.0.1.1...
telnet: Unable to connect to remote host: Connection refused
这是 Rpi 的东西,还是 Flask 的东西?
原来是Flask的东西
host (Optional[str]) – the hostname to listen on. Set this to '0.0.0.0' to have the server available externally as well. Defaults to
'127.0.0.1' or the host in the SERVER_NAME config variable if present.
所以,修复我的 Flask 运行 调用:
app.run(host="0.0.0.0", port=config.CONTROLLERS[whoami]["port"],
debug=config.DEBUG, use_reloader=False)
现在,我的端口正在监听世界其他地方:
pi@brs-tv:~ $ sudo netstat -lptu
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:8087 0.0.0.0:* LISTEN 1213/python
我现在也可以从另一台机器连接:
Ricos-vt220:~ % telnet brs-tv.local 8087
Trying fe80::3d7:b64:bb26:14e0...
telnet: connect to address fe80::3d7:b64:bb26:14e0: Connection refused
Trying 192.168.86.29...
Connected to brs-tv.local.
Escape character is '^]'.
GET /cmd
我在我的 Raspi 上的守护进程中安装了烧瓶 运行ning。
@app.route("/cmd",methods = ['POST', 'GET'])
def cmd():
if request.method == 'GET':
order_obj = request.args.to_dict(flat=True)
else:
order_obj = request.get_json(force=True)
response = jsonify(controller_obj.act_on_order(order_obj))
response.headers.add('Access-Control-Allow-Origin', '*')
return response
app.run(port=8087, debug=config.DEBUG, use_reloader=False)
当我 运行 这个应用程序时,我可以看到它正在侦听端口 8087:
pi@brs-tv:~/brs $ sudo netstat -lptu
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 localhost:8087 0.0.0.0:* LISTEN 4133/python
当我使用本地主机远程登录到本地端口时,它工作正常。
pi@brs-tv:~/brs $ telnet localhost 8087
Trying ::1...
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
GET /cmd
但是当我本地 telnet 到它的本地地址时,我得到连接被拒绝:
pi@brs-tv:~/brs $ telnet brs-tv.local 8087
Trying 127.0.1.1...
telnet: Unable to connect to remote host: Connection refused
这是 Rpi 的东西,还是 Flask 的东西?
原来是Flask的东西
host (Optional[str]) – the hostname to listen on. Set this to '0.0.0.0' to have the server available externally as well. Defaults to '127.0.0.1' or the host in the SERVER_NAME config variable if present.
所以,修复我的 Flask 运行 调用:
app.run(host="0.0.0.0", port=config.CONTROLLERS[whoami]["port"],
debug=config.DEBUG, use_reloader=False)
现在,我的端口正在监听世界其他地方:
pi@brs-tv:~ $ sudo netstat -lptu
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:8087 0.0.0.0:* LISTEN 1213/python
我现在也可以从另一台机器连接:
Ricos-vt220:~ % telnet brs-tv.local 8087
Trying fe80::3d7:b64:bb26:14e0...
telnet: connect to address fe80::3d7:b64:bb26:14e0: Connection refused
Trying 192.168.86.29...
Connected to brs-tv.local.
Escape character is '^]'.
GET /cmd