Python 3.x 为什么我的python wsgi服务器函数在每个请求中运行两次?
我用python3和WSGI模块编写了一个简单的web服务器:Python 3.x 为什么我的python wsgi服务器函数在每个请求中运行两次?,python-3.x,wsgiserver,Python 3.x,Wsgiserver,我用python3和WSGI模块编写了一个简单的web服务器: #!/usr/bin/python3 from wsgiref.simple_server import make_server port = 80 count = 0 def hello_app(environ, start_response): global count status = '200 OK' # HTTP Status headers = [('Content-type', 'text
#!/usr/bin/python3
from wsgiref.simple_server import make_server
port = 80
count = 0
def hello_app(environ, start_response):
global count
status = '200 OK' # HTTP Status
headers = [('Content-type', 'text/plain')] # HTTP Headers
start_response(status, headers)
response = "hello number {}".format(count)
count += 1
return( [response.encode()] )
httpd = make_server('', port, hello_app)
print("Serving HTTP on port {}...".format(port))
# Respond to requests until process is killed
httpd.serve_forever()
它工作得很好,但每次我向broswer发出请求时,计数都会增加2,而不是1。如果我注释掉“count+=1”,它只会保持在零。为什么?这是一个非常愚蠢的问题-浏览器会自动为每个请求请求“favicon”文件。通过使用解决方案进行修复。如果您已经解决了问题,请发布“答案”,而不是在问题中发布解决方案。谢谢。今天我在编写代码时,现在将调到您的音乐中。