Python瓶在404后没有反应

2024-04-24 06:15:07 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在运行一个瓶子v0.12.15服务器,它正在0.0.0.0:9000上侦听。我运行它的机器的ip是192.168.0.16

我设置的唯一路由是重定向任何连接到静态index.html页的人

每当我访问一个随机的url,它没有从我网络上的一个设备设置路由,即192.168.0.16:9000/asdf,我总是得到一个Error: 404,就像预期的那样,并且可以返回到索引页

但是,当从2个设备访问时,如果我在设备1上的404 Error上着陆,访问设备2上的192.168.0.16:9000/asdf(应该是404)这样的URL只会导致瓶子服务器挂起,直到我刷新另一个设备上的页面,它才给出响应

我尝试添加一个错误路由,每当得到404时,它就会给出一个HTML页面,但同样的问题仍然存在

我不知道是什么原因造成的,或者我可以做什么来修复它,所以任何帮助都将不胜感激

我正在运行的runserv.py文件的完整部分如下所示:

from bottle import *

#error handling


@error(404)
def error404(error):
    return static_file("404.html", 
    root="./errorFiles")

@route('/')
def slash():
    redirect("/index")

@route('')
def empty():
    redirect("/index")

@route('/index')
def index():
    return static_file("index.html", root="./webpageFiles")

run(host='0.0.0.0', port=9000, debug=True, reloader=True)

Tags: 服务器瓶子路由indexreturndefhtmlstatic