Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 为什么我的python wsgi服务器函数在每个请求中运行两次?_Python 3.x_Wsgiserver - Fatal编程技术网

Python 3.x 为什么我的python wsgi服务器函数在每个请求中运行两次?

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

我用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/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”文件。通过使用解决方案进行修复。

如果您已经解决了问题,请发布“答案”,而不是在问题中发布解决方案。谢谢。今天我在编写代码时,现在将调到您的音乐中。