烧瓶,无法分配请求的地址 [英] Flask, cannot assign requested address

查看:59
本文介绍了烧瓶,无法分配请求的地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在远程服务器上运行Flask应用程序,因此可以从其他计算机上访问它.服务器有一个公共IP,我将烧瓶配置为在该IP上运行.但是,当我运行脚本时,会得到以下回溯

I'm trying to run a flask app on a remote server, so I can access it from other computers. The server has a public IP and I configured the flask to run on that IP. But when I run the script I get the following traceback

注意:我已经从回溯和我的代码中删除了公共IP.

Note: I've removed the public IP from the traceback and my code.

 * Running on **public ip** 
Traceback (most recent call last):
  File "testServer.py", line 14, in <module>
    app.run(host='62.60.19.189',port=5000)
  File "/usr/lib/python2.6/site-packages/flask/app.py", line 772, in run
    run_simple(host, port, self, **options)
  File "/usr/lib/python2.6/site-packages/werkzeug/serving.py", line 710, in run_simple
    inner()
  File "/usr/lib/python2.6/site-packages/werkzeug/serving.py", line 692, in inner
    passthrough_errors, ssl_context).serve_forever()
  File "/usr/lib/python2.6/site-packages/werkzeug/serving.py", line 486, in make_server
    passthrough_errors, ssl_context)
  File "/usr/lib/python2.6/site-packages/werkzeug/serving.py", line 410, in __init__
    HTTPServer.__init__(self, (host, int(port)), handler)
  File "/usr/lib64/python2.6/SocketServer.py", line 402, in __init__
    self.server_bind()
  File "/usr/lib64/python2.6/BaseHTTPServer.py", line 108, in server_bind
    SocketServer.TCPServer.server_bind(self)
  File "/usr/lib64/python2.6/SocketServer.py", line 413, in server_bind
    self.socket.bind(self.server_address)
  File "<string>", line 1, in bind
socket.error: [Errno 99] Cannot assign requested address

这是我的代码

import flask

app = flask.Flask("My app")

@app.route('/myroute', methods=['POST'])
def foobar():
        print flask.request.form
        return '<br>'.join('{0}: {1}'.format(*pair) for pair in flask.request.form.items())




if __name__ == '__main__':
    app.run(host='public IP',port=5000)

推荐答案

您只能直接绑定到已为其配置服务器的IP地址.在运行网络地址转换(NAT)的路由器后面,您的内部IP地址将有所不同.

You can only directly bind to an IP address that the server has been configured for; behind a router running Network Address Translation (NAT) your internal IP address will be different.

直接绑定到该内部IP地址,或使用'0.0.0.0'侦听所有接口.您可能仍需要配置路由器,以将特定端口转发到内部服务器.

Either bind directly to that internal IP address, or use '0.0.0.0' to listen on all interfaces. You may still need to configure the router to forward a specific port to your internal server.

这篇关于烧瓶,无法分配请求的地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆