[mod_python] "TypeError: argument 2 must be a mapping" and other things

Jorey Bump list at joreybump.com
Tue Sep 20 17:58:53 EDT 2005


Daniel Winkler wrote:
> Hello together,
> 
> I am trying to write a little web application with Apache2, mod_python
> and MySQL. Unfortunately I have to fight with some strange effects:
> 
> E.g.:
>   acl = db.cursor()
>   acl.execute("SELECT * FROM acl WHERE c = %s AND d = %s;",
>               (cID, dID))
> with cID and dID as integers causes an "TypeError: argument 2 must be a
> mapping". Sometimes. I tried to restart the apache server and -- it
> worked, but after reloading the SAME page without any modifications this
> error occured again, also on similar SQL statements in other parts of
> the code.
> I already checked the arguments: They are just normal integers.
> I tested the code with the interactive interface: everything worked
> fine. (the code sniplet mentioned above is independet from Apache and
> special mod_python features)
> 
> Could someone please give me a hint how to debug this and to avoid these
> (non-deterministic) errors? What might I have done wrong?

You're mixing python string replacement with placeholders. You need to 
escape the placeholders (and the semicolon isn't necessary here):

acl.execute("SELECT * FROM acl WHERE c = %%s AND d = %%s", (cID, dID))


More information about the Mod_python mailing list