I Have an Excuse, Honest
Not for any lack of progress, as I’ve got a webpage displaying data from the database and the rest of the day to add to it. I have an excuse for the part I played in the following tale.
In order to start with the web side of things, all I wanted to do was select out rows from the MapRegion table and the rows from the Location table that belong to those regions. The first python page then looked like:
from mod_python import apache
import MySQLdb
def handler(req):
db=MySQLdb.connect( ... )
c=db.cursor()
c.execute("""SELECT idMapRegion,name FROM MapRegion;""")
MapRows = c.fetchall()
for i in range(len(MapRows)):
req.write("Map: ")
req.write(str(MapRows[i][1]))
mapID = MapRows[i][0]
c.execute("""SELECT positionX,positionY,radius FROM Location WHERE idMapRegion=%s;""",mapID)
LocRows=c.fetchall()
for j in range(len(LocRows)):
req.write(" - Location: X=")
req.write(str(LocRows[j][0]))
req.write(", Y=")
req.write(str(LocRows[j][1]))
req.write(", radius=")
req.write(str(LocRows[j][2]))
c.close()
return apache.OK
Yes, yes, there’s all sorts of things wrong with it, but it’s just some suck-it-and-see code, calm down (and ignore the \” bits, that’s some odd translation going on, not the original code). Anyway, this produced exactly nothing. No output. I stuck a req.write(“Hello”) at the top and that worked, then moved the line down until finding that nothing happened after the execute(). Not only that, but my browser (IE via AvantBrowser) would start taking 100% of the CPU and need restarting. I converted the code to a normal .py file with print() output and it worked fine.
Google hunting commenced… and I found this page explaining that the php4 module for Apache would break mod_python’s use of MySQL if it was using its own libraries. This seems like a rather poor move on the part of the PHP team, but what do I know? The cure was to recompile it and point it at the MySQL directory. As I’ve mentioned before, I’m not a big fan of this stuff, and this experience hardly convinced me I’m wrong.
First, the option to generate a .so module for Apache 2 is –with-apxs2=path/to/apxs, I had to point the mod_python build at apxs, so that’s not an issue. The other option I needed is for the MySQL libs: –with-mysql=path/to/mysql. Okay, so my headers are in /usr/local/mysql, so surely that’s what to use? No, configure tells me it can’t find the headers there. Google hunt! After finding some similarly confused people, it seems that you need to be a bit more expansive, despite the fact that the headers are definitely in /usr/local/mysql, PHP’s configure actually wants to be told to look in /usr. Why? I don’t know.
Configure completes, and I do a make and make install, restart apache and… the same problem. When I look at the .so module, it hasn’t been replaced by the install, so I go back and try again, no joy. I must have spent about an hour searching the web for information on this before just having a whinge in #python. Just out of desperation, I copied my configure command to the channel to see if someone knew if I needed another option:
./configure --with-mysql=/usr --with-apsx2=/usr/sbin/apsx
Some advice was offered, and I was quite rightly being suspected of simply not seeing an error message. And then a chap or chapette by the handle Yhg1s offered the following:
“–with-apxs, not –with-apsx”
I thanked him and made a mental note to beat my head against something later. Then I fixed the error, the build worked and my python code was freed from the tyranny of the PHP libs.
Again, Linux, mainstream… no.
Oh, my excuse? PSX was a term for the Playstation before it was called Playstation and it stuck in games dev circles. I’ve typed psx far more than I’ve ever typed pxs. A poor excuse, sure, but I’m sticking with it, and seeing as I made the same mistake when writing the earlier post on installing mod_python, I may need the excuse again in the future.

