0

I wrote a simple web server with python3 and the WSGI modules:

#!/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()

And it works fine, but every time I make a request from a broswer, the count increments by 2, not by one. If I comment out the "count += 1", it just stays at zero. Why?

Joshua Schlichting
  • 3,110
  • 6
  • 28
  • 54
danmcb
  • 289
  • 1
  • 12

1 Answers1

0

Problem was a very silly one - the browser was requesting the "favicon" file automatically for every request. Fixed by using the solution here.

danmcb
  • 289
  • 1
  • 12