我正在尝试在远程服务器上运行一个烧瓶应用程序,因此我可以从其他计算机访问它。服务器有一个公共IP,我配置烧瓶在该IP上运行。但是当我运行脚本时,我得到以下追溯
注意:我已从追踪和我的代码中删除了公共IP。
* 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)
答案 0 :(得分:7)
您只能直接绑定到已配置服务器的IP地址;在运行网络地址转换(NAT)的路由器后面,您的内部IP地址将不同。
直接绑定到该内部IP地址,或使用'0.0.0.0'
监听所有接口。您可能仍需要配置路由器以将特定端口转发到内部服务器。
答案 1 :(得分:1)
要将套接字绑定到的IP必须直接在计算机的接口上可用。这似乎不是这种情况。