0
我想連接我自己的服務器與亞馬遜ec 2實例創建的IP地址。但是,每當我把這個代碼,我得到一個錯誤消息。代碼是:連接我的IP地址到瓶服務器錯誤 - Ubuntu的ipython
from flask import Flask, request
visitor_counter = 0
webserver = Flask("MyFirstWebServer")
import datetime
import time
@webserver.route('/')
def hello_world():
# stop_server()
return 'Hello James, it is now ' + str(datetime.date.today())
@webserver.route('/testSU')
def hello_su():
# stop_server()
global visitor_counter
visitor_counter += 1
return 'Hello! You are visitor #{i}'.format(i=visitor_counter)
def start_server():
global visitor_counter
visitor_counter = 0
webserver.run(host='aaa.bbb.cc.ddd', port=5000)
return
def stop_server():
shutdown_after_request = request.environ.get('werkzeug.server.shutdown')
shutdown_after_request()
return
start_server()
我得到的錯誤消息是「OSError:[Errno 99]無法分配請求的地址」。這是錯誤信息的細節,我得到當我運行python的筆記本:
OSError Traceback (most recent call last)
<ipython-input-4-2dda11743df7> in <module>()
----> 1 start_server()
<ipython-input-1-dcbe603433f4> in start_server()
30 global visitor_counter
31 visitor_counter = 0
---> 32 webserver.run(host='aaa.bbb.cc.ddd', port=5000)
33 return
34
/usr/local/lib/python3.5/dist-packages/flask/app.py in run(self, host, port, debug, **options)
839 options.setdefault('use_debugger', self.debug)
840 try:
--> 841 run_simple(host, port, self, **options)
842 finally:
843 # reset the first request information if the development server
/usr/local/lib/python3.5/dist-packages/werkzeug/serving.py in run_simple(hostname, port, application, use_reloader, use_debugger, use_evalex, extra_files, reloader_interval, reloader_type, threaded, processes, request_handler, static_files, passthrough_errors, ssl_context)
706 reloader_type)
707 else:
--> 708 inner()
709
710
/usr/local/lib/python3.5/dist-packages/werkzeug/serving.py in inner()
668 processes, request_handler,
669 passthrough_errors, ssl_context,
--> 670 fd=fd)
671 if fd is None:
672 log_startup(srv.socket)
/usr/local/lib/python3.5/dist-packages/werkzeug/serving.py in make_server(host, port, app, threaded, processes, request_handler, passthrough_errors, ssl_context, fd)
562 else:
563 return BaseWSGIServer(host, port, app, request_handler,
--> 564 passthrough_errors, ssl_context, fd=fd)
565
566
/usr/local/lib/python3.5/dist-packages/werkzeug/serving.py in __init__(self, host, port, app, handler, passthrough_errors, ssl_context, fd)
474 socket.SOCK_STREAM)
475 port = 0
--> 476 HTTPServer.__init__(self, (host, int(port)), handler)
477 self.app = app
478 self.passthrough_errors = passthrough_errors
/usr/lib/python3.5/socketserver.py in __init__(self, server_address, RequestHandlerClass, bind_and_activate)
438 if bind_and_activate:
439 try:
--> 440 self.server_bind()
441 self.server_activate()
442 except:
/usr/lib/python3.5/http/server.py in server_bind(self)
136 def server_bind(self):
137 """Override server_bind to store the server name."""
--> 138 socketserver.TCPServer.server_bind(self)
139 host, port = self.socket.getsockname()[:2]
140 self.server_name = socket.getfqdn(host)
/usr/lib/python3.5/socketserver.py in server_bind(self)
452 if self.allow_reuse_address:
453 self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
--> 454 self.socket.bind(self.server_address)
455 self.server_address = self.socket.getsockname()
456
我使用的終端,看看是否有任何其他的服務器/程序上的5000端口開放,卻沒有一個。 。這可能是我的問題嗎?
'aaa.bbb.cc.ddd'可能不映射到分配給該框的IP地址。大多數情況下,您希望將其設置爲'localhost'或'0.0.0.0'。 – jordanm