Python 2.0.1 bug?

TheDustbustr thedustbustr at aol.com
Fri Jul 20 15:53:30 CEST 2001


Sutdy the following code:

# BEGIN CODE BLOCK
# simple webserver
import socket

HOST = ''     # empty string meaning localhost
PORT = 8080
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((HOST, PORT))
s.listen(1)

while 1:
    conn, addr = s.accept()
    print 'Connected by', addr
    data = conn.recv(1024)
    print data
    conn.send(data)     # reference point 1
    conn.close()
# END CODE BLOCK

When you run this program then point your webbrowser to localhost:8080, you
SHOULD see your GET / HTTP/1.1 request echoed to the screen (the "webpage"), as
well as echoed to the console.  Well, under Python 1.5.2 running under Linux,
it does.  Running 2.0.1 under Windows 95, it doesn't, *nothing* is printed to
the webbrowser.  Reference point 1 can be changed to thus to make it work: 
conn.send(data+data)   Thus under Windows Py2.0.1 it prints the GET request to
the webbrowser ONCE.  Under Linux Py1.5.2 it prints it TWICE as expected). 
Another test with curious results is to change the reference line to this: 
conn.send("first part" + data + "second part")   This prints the string "second
part" to the webbrowser, nothing more.

Hmmm, any known workarounds for this problem?  Other python-based servers have
worked on my machine (like the samples included in the docs).

Thanks, Dustin



More information about the Python-list mailing list