我正在使用瓶子,并编写了一个简单的应用程序
from bottle import *
@route("/")
def index():
return "This is a test."
run(host="0.0.0.0", port=8080)
当我运行此操作时,我收到错误消息:
Traceback (most recent call last):
File "C:\Users\James\Desktop\application.py", line 7, in <module>
run(host="0.0.0.0", port=8080)
File "C:\Python34\lib\site-packages\bottle.py", line 3117, in run
server.run(app)
File "C:\Python34\lib\site-packages\bottle.py", line 2771, in run
srv = make_server(self.host, self.port, app, server_cls, handler_cls)
File "C:\Python34\lib\wsgiref\simple_server.py", line 153, in make_server
server = server_class((host, port), handler_class)
File "C:\Python34\lib\socketserver.py", line 429, in __init__
self.server_bind()
File "C:\Python34\lib\wsgiref\simple_server.py", line 50, in server_bind
HTTPServer.server_bind(self)
File "C:\Python34\lib\http\server.py", line 133, in server_bind
socketserver.TCPServer.server_bind(self)
File "C:\Python34\lib\socketserver.py", line 440, in server_bind
self.socket.bind(self.server_address)
OSError: [WinError 10013] An attempt was made to access a socket in a way forbid
den by its access permissions
查看其他一些SO帖子,似乎我需要允许它通过防火墙。我做到了:
但错误仍然存在,我该怎么做才能解决这个问题?
答案 0 :(得分:1)
尝试使用127.0.0.1而不是localhost
from bottle import route, run, template
@route('/hello/<name>')
def index(name):
return template('<b>Hello {{name}}</b>!', name=name)
run(host='127.0.0.1', port=8080)