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

Daniel Winkler mailings at danielwinkler.de
Wed Sep 21 05:47:32 EDT 2005

Hi Jorey,

Am Dienstag, den 20.09.2005, 19:24 -0400 schrieb Jorey Bump:
> ... and possibly some of the errors you're seeing, as well, for context? 
> Are you sure the arguments referred to are in fact the ones in the 
> query, and not from some other part of the code?
Okay, I'll try to extract the important parts ...

index.py: ***********************************

from mod_python import psp
import dirigent
import chor

def startseite(req, chorid=0): #called startseite?chorid=1 or so
    dirigent.id = dirigent.ermittle_dirigent(req)
    chor.id = chor.ermittle_chor(chorid, dirigent.id)

datenbank.py: ********************************

import MySQLdb
db = MySQLdb.connect(host="localhost",

chor.py: *************************************

from datenbank import db

id = 0

def _acltest_ok(chorID, dirigentID):
    acl = db.cursor()
(*) acl.execute("SELECT chor FROM acl WHERE chor = %s AND dirigent = %s", (chorID, dirigentID))
    return (int(acl.rowcount) > 0)

def ermittle_chor(chorID, dirigentID):
    if ( (chorID > 0)
         and _acltest_ok(chorID, dirigentID) ):
        return chorID
        choere = db.cursor()
(*)     choere.execute("SELECT chor FROM acl WHERE dirigent = %s;", (dirigentID))

        if int(choere.rowcount) == 1:
            chor = choere.fetchone()
            return chor[0]
            return 0

The (*) marked lines are those where the error occurs most at the
moment. E.g.:

od_python error: "PythonHandler mod_python.publisher"

Traceback (most recent call last):

  File "/usr/lib/python2.3/site-packages/mod_python/apache.py", line 299, in HandlerDispatch
    result = object(req)

  File "/usr/lib/python2.3/site-packages/mod_python/publisher.py", line 136, in handler
    result = util.apply_fs_data(object, req.form, req=req)

  File "/usr/lib/python2.3/site-packages/mod_python/util.py", line 361, in apply_fs_data
    return object(**args)

  File "<somewhere>/index.py", line 49, in lied
    chor.id = chor.ermittle_chor(chorid, dirigent.id)

  File "<somewhere>/chor.py", line 18, in ermittle_chor
    if ( (chorID > 0)

  File "<somewhere>/chor.py", line 11, in _acltest_ok
    acl.execute("SELECT chor FROM acl WHERE chor = %s AND dirigent = %s", (chorID, dirigentID))

  File "/usr/lib/python2.3/site-packages/MySQLdb/cursors.py", line 132, in execute
    self.errorhandler(self, TypeError, m)

  File "/usr/lib/python2.3/site-packages/MySQLdb/connections.py", line 33, in defaulterrorhandler
    raise errorclass, errorvalue

TypeError: argument 2 must be a mapping

The first time I load the page, everything is fine. This error occurs
after the first or second page reload (same code, same parameters).
Don't ask me why ...

I had even more strange errors like "syntax errors" in a line called
"c = 1" in a PSP file, but I cannot reproduce them at the moment. (maybe
after the problem above is fixed :-)
BTW, I am new to Python so if you have additional hints what can be done
better: everything is welcome.
Okay, yes, I know that global variables aren't very nice, but I thought
it is not necessary to build a class just for one object ... ;-)


More information about the Mod_python mailing list