quetz-mod_python-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Graham Dumpleton" <grah...@dscpl.com.au>
Subject Re: mod-python error
Date Wed, 15 Mar 2006 22:52:58 GMT
Following may or may not be relevant.

BTW, have you tried your sample code outside of context of mod_python.
Ie., extract out main bit and run it as command line script.

Patty wrote ..
> This is the piece of code:
> 
> # Connect to the database
> conn =  MySQLdb.connect(host = "localhost", user = "root", passwd = "",
>                         db ="ants_control_center")
> cursor = conn.cursor()
> 
> 
> def ask(req, host, target):
> 
>     gtarget = "%s" % target
>     ghost = "%s" % host
>     cursor.execute("""                     #This is line 18
>     SELECT date FROM targets WHERE target_name = %s""",(gtarget))

In Python, saying:

  (gtarget)

is the same as:

  gtarget

That is, a tuple will only be created for a single item if written as:

  (gtarget,)

Thus, if cursor.execute() expects a tuple, use latter form.

>     result = cursor.fetchone()
>     conn.commit()
> 
>     if ((gtarget == 'bl') | (gtarget == 'bs') | (gtarget == 'nl') |
>           (gtarget == 'bx')):

Traditionally one uses "or" and not "|" for logical or. The "|" operator is
bitwise or and has special meaning when arguments are integers. It
might work like "or" for booleans, but best to use "or" as that is what
most people will be used to.

>         cursor.execute("UPDATE targets SET date = %s WHERE target_name
> = %s",
>                        (datetime.date.today(),gtarget))
>         conn.commit()
>         return compare_hosts(ghost,gtarget)                      
> 
>     # This one takes care of the rest
>     if (datetime.date.today() == result[0]):
>         return compare_hosts(ghost,gtarget)
>     else:
>         return set_host_percentage(ghost,gtarget)
> 
> ***************************************************************************
> 
> This is the error I'm getting:
> 
> <pre>
> Mod_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 "/var/www/html/mptest/ask.py", line 18, in ask
>     cursor.execute("""
>  
>   File "/usr/lib/python2.3/site-packages/MySQLdb/cursors.py", line 137,
> in execute
>     self.errorhandler(self, exc, value)
>  
>   File "/usr/lib/python2.3/site-packages/MySQLdb/connections.py", line
> 33, in
> defaulterrorhandler
>     raise errorclass, errorvalue
>  
> AttributeError: 'NoneType' object has no attribute 'literal'
>  
> </pre>

Mime
View raw message