mod-python error
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Web Servers reviews > Apache Server configuration support > Apache Mod-Python > mod-python error




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    mod-python error  
Patty


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
03-15-06 10:46 PM

Hi,
I'm really hoping someone can help me understand what is wrong with this pie
ce
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, i
n
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 exe
cute
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>








[ Post a follow-up to this message ]



    Re: mod-python error  
Graham Dumpleton


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
03-15-06 10: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>






[ Post a follow-up to this message ]



    Re: mod-python error  
Joseph Barillari


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
03-16-06 12:45 PM

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 p
iece
> 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 13
6, 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>
>
>






[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 03:41 AM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register