[Tutor] 500 (hit counter)
Kyle Babich
python@kyle.sent.com
Wed Jul 16 19:53:02 2003
On Thu, 17 Jul 2003 01:36:57 +0200, "Magnus Lyck=E5" <magnus@thinkware.se>
said:
> What I see here is a Python script with no #! line in the
> beginning. If you try to execute that as a CGI script, it
> will run as a bourne shell script, yes? That's likely to
> cause errors...
It's there, I just didn't copy and paste that part (by accident).
>=20
> If you have a web server setup that manages to run this with
> python despite the lack of proper #!, make sure that you
> run Python unbuffered: "python -u".
>=20
> I'd also try putting "import cgitb; cgitb.enable()" in the
> beginning if Python was recent enough.
I'll try this. I know for a fact that my admin is running an older
version of python. It still uses open() instead of file().
>=20
> At 16:33 2003-07-16 -0500, Kyle Babich wrote:
> >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 =3D os.stat('/data.txt')[stat.ST_SIZE]
> > ip =3D os.environ['REMOTE_ADDR']
> >
> > getHit =3D open('/ips.txt', 'r')
> > hitIps =3D getHit.readlines()
> > getHit.close()
> >
> > add =3D 1
> > for each in hitIps:
> > each =3D string.strip(each)
> > if each =3D=3D ip:
> > add =3D 0
> > else:
> > pass
> >
> > if add =3D=3D 1:
> > addIp =3D open('/ips.txt', 'a')
> > addIp.write("\n" . ip)
> > addIp.close()
> >
> > current +=3D 1
> > addHit =3D 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
> >
> >_______________________________________________
> >Tutor maillist - Tutor@python.org
> >http://mail.python.org/mailman/listinfo/tutor
>=20
> --
> Magnus Lycka (It's really Lyckå), magnus@thinkware.se
> Thinkware AB, Sweden, www.thinkware.se
> I code Python ~ The Agile Programming Language=20
>=20
>=20
--
Kyle