[Tutor] 500 (hit counter)

Kyle Babich python@kyle.sent.com
Wed Jul 16 17:34:02 2003


Pretty simple, it's a hit counter that gives me a 500...

###############################
print "Content-type: text/html\r\n\r\n"

import os
import stat
import string

def increment () :
    current = os.stat('/data.txt')[stat.ST_SIZE]
    ip = os.environ['REMOTE_ADDR']

    getHit = open('/ips.txt', 'r')
    hitIps = getHit.readlines()
    getHit.close()

    add = 1
    for each in hitIps:
        each = string.strip(each)
        if each == ip:
            add = 0
        else:
            pass

    if add == 1:
        addIp = open('/ips.txt', 'a')
        addIp.write("\n" . ip)
        addIp.close()
        
        current += 1
        addHit = open('/data.txt', 'a')
        addHit.write('k')
        addHit.close()

    return current

print increment()
###############################

It is chmod'd to 755 and I also have ips.txt and data.txt that are both
777.  Why the 500?  I checked the error logs and it says 'Premature end
of script headers', which seems to be a standard error, except I didn't
do anything different with these headers than I do with headers in any
other program I've written.
--
Kyle