我試圖在遠程服務器上運行燒瓶應用程序,所以我可以從其他計算機訪問它。服務器有一個公共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)
該服務器*直接*配置爲在該IP地址上運行,或者您在路由器後面運行,* it *具有IP地址(例如,您的服務器具有私有IP地址,路由器使用NAT - 網絡地址轉換)? – 2014-10-09 14:22:19
順便提一下,這是*不是* Flask獨有的問題。 – 2014-10-09 14:22:36
不,我在連接到VPN後使用不同的IP連接到服務器,我在遠程服務器上運行python代碼,並獲得了一個公共IP來運行燒瓶。 – cyberbemon 2014-10-09 14:25:58