Apache Mod-Python - mod-python error

This is Interesting: Free IT Magazines  
Home > Archive > Apache Mod-Python > March 2006 > mod-python error





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author mod-python error
Patty

2006-03-15, 5:46 pm

Hi,
I'm really hoping someone can help me understand what is wrong with this piece
of code.
Thanks,
Patty

This is how I call my function:
http://hostname/mptest/ask.py/ask?h...&target=atarget

****************************************
***********************************
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))
result = cursor.fetchone()
conn.commit()

if ((gtarget == 'bl') | (gtarget == 'bs') | (gtarget == 'nl') |
(gtarget == 'bx')):
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>



Graham Dumpleton

2006-03-15, 5:46 pm

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>


Joseph Barillari

2006-03-16, 7:45 am

That looks like an SQL error, rather than an MP error. I'd try calling
it without MP present (with the same arguments, of course...).

Joe

On Wed, Mar 15, 2006 at 10:34:00PM +0000, Patty wrote:
> Hi,
> I'm really hoping someone can help me understand what is wrong with this piece
> of code.
> Thanks,
> Patty
>
> This is how I call my function:
> http://hostname/mptest/ask.py/ask?h...&target=atarget
>
> ****************************************
***********************************
> 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))
> result = cursor.fetchone()
> conn.commit()
>
> if ((gtarget == 'bl') | (gtarget == 'bs') | (gtarget == 'nl') |
> (gtarget == 'bx')):
> 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>
>
>


Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com