作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试将我自己的服务器与 amazon ec 2 实例创建的 IP 地址连接起来。但是,每当我输入此代码时,都会收到一条错误消息。代码是:
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 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
最佳答案
这段代码对我有用 试试看
import os
from flask import Flask
__author__ = 'Rajshekhar Horatti'
app = Flask(__name__)
APP_ROOT = os.path.dirname(os.path.abspath(__file__))
@app.route("/")
def main():
return "hello world"
if __name__ == "__main__":
app.run(host='0.0.0.0', port=8080, debug=True)
host = 0.0.0.0
并检查您激活了哪个端口并分配该端口
关于python - 将我的 IP 地址连接到 flask 服务器时出错 - ubuntu ipython,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42471666/
我正在开发一个 voip 调用应用程序。我需要做的是在接到来电时将 Activity 带到前台。我在应用程序中使用 Twilio,并在收到推送消息时开始调用。 问题是我试图在接到任何电话时显示 Act
我是一名优秀的程序员,十分优秀!