473,385 Members | 1,829 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

mod_python

I can't figure out how to build this type of program using the
publisher handler. I have the following connected to the program
SetHandler python-program
PythonHandler mod_python.publisher
PythonDebug On

But what I would like to do would be have a german word as the
parameter in the HTTP request and have the english world printed out on
the screen. Yes this will be a small dictionary but I just want to be
able to understand how to build the program and have it work without
any errors. Thanks for any help.

PS I understand the example of printing the say portion in the
mod_python manual but can't get past that.

Again Thanks!!

Nov 5 '05 #1
6 3614
I have created the following database but the following errors occur
when trying to execute the code.

html source:
<html>
<body>
Click here to display information from Chocolate menu:
<form action ="form.py/display" method="POST">
<p>
Press to view the display
<input type="submit">
</p>
</form>
<br>
Please provide data for chocolate to be added:
<p>
<form action ="form.py/addchocolate" method="POST">
<p>
Name: <input type="text" name="z_Name" maxlength="30"><br>
Rating: <input type="text" name="z_rating" maxlength="3"><br>
Price : <input type="text" name="z_price" maxlength="5"><br>
<input type="submit">
</p>
</form>
</body>
</html>

form.py source

import MySQLdb

def addchocolate(z_Name, z_rating, z_price):

# make sure the user provided all the parameters
if not (z_Name and z_rating and z_price):
return "A required parameter is missing, \
please go back and correct the error"
db =
MySQLdb.connect(host="localhost",user="hayward",pa sswd="hayward",db="hayward")
cursor = db.cursor()
cursor.execute(
"""INSERT INTO InventoryList (artist, title, rating) VALUES (%s,
%s, %s)""", (z_Name, z_rating, z_price) )
db.commit()
cursor.close()
db.close()

def display(rating):
db =
MySQLdb.connect(host="localhost",user="hayward",pa sswd="hayward",db="hayward")
cursor = db.cursor()
cursor.execute("""SELECT * FROM InventoryList""")
result = cursor.fetchall()
cursor.close()
db.close()
parsesongs(result)
return

def parsesongs(rawstring):
print 'Chocolate Inventory'
print
'---------------------------------------------------------------'
print 'Name Rating
Price '
print
'---------------------------------------------------------------'
for i in range (0, len(rawstring)):
table = ''
Name = rawstring[i][0]
table = table + Name
for j in range (0, (29 - len(Name))):
table = table + ' '
Rating = rawstring[i][1]
table = table + Rating
for k in range (0, (29 - len(Rating))):
table = table + ' '
Price = str(rawstring[i][2])
table = table + Price
print table
print
'---------------------------------------------------------------'
return

errors that occur
press display:
Mod_python error: "PythonHandler mod_python.publisher"

Traceback (most recent call last):

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

File "/usr/lib/python2.3/site-packages/mod_python/publisher.py", line
173, in handler
result = apply(object, (), args)

TypeError: display() takes exactly 1 argument (0 given)

press the addition of the items:
Mod_python error: "PythonHandler mod_python.publisher"

Traceback (most recent call last):

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

File "/usr/lib/python2.3/site-packages/mod_python/publisher.py", line
173, in handler
result = apply(object, (), args)

File
"/home/hayward/public_html/Homework/Python_Executable_Publisher/form.py",
line 11, in addchocolate
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

OperationalError: (1054, "Unknown column 'artist' in 'field list'")

Thanks for the help

Nov 6 '05 #2
Little wrote:
I have created the following database but the following errors occur
when trying to execute the code.

html source:
<html>
<body>
Click here to display information from Chocolate menu:
<form action ="form.py/display" method="POST">
<p>
Press to view the display
<input type="submit">
</p>
</form>
<br>
Please provide data for chocolate to be added:
<p>
<form action ="form.py/addchocolate" method="POST">
<p>
Name: <input type="text" name="z_Name" maxlength="30"><br>
Rating: <input type="text" name="z_rating" maxlength="3"><br>
Price : <input type="text" name="z_price" maxlength="5"><br>
<input type="submit">
</p>
</form>
</body>
</html>

form.py source

import MySQLdb

def addchocolate(z_Name, z_rating, z_price):

# make sure the user provided all the parameters
if not (z_Name and z_rating and z_price):
return "A required parameter is missing, \
please go back and correct the error"
db =
MySQLdb.connect(host="localhost",user="hayward",pa sswd="hayward",db="hayward")
cursor = db.cursor()
cursor.execute(
"""INSERT INTO InventoryList (artist, title, rating) VALUES (%s,
%s, %s)""", (z_Name, z_rating, z_price) )
db.commit()
cursor.close()
db.close()

def display(rating):
db =
MySQLdb.connect(host="localhost",user="hayward",pa sswd="hayward",db="hayward")
cursor = db.cursor()
cursor.execute("""SELECT * FROM InventoryList""")
result = cursor.fetchall()
cursor.close()
db.close()
parsesongs(result)
return

def parsesongs(rawstring):
print 'Chocolate Inventory'
print
'---------------------------------------------------------------'
print 'Name Rating
Price '
print
'---------------------------------------------------------------'
for i in range (0, len(rawstring)):
table = ''
Name = rawstring[i][0]
table = table + Name
for j in range (0, (29 - len(Name))):
table = table + ' '
Rating = rawstring[i][1]
table = table + Rating
for k in range (0, (29 - len(Rating))):
table = table + ' '
Price = str(rawstring[i][2])
table = table + Price
print table
print
'---------------------------------------------------------------'
return

errors that occur
press display:
Mod_python error: "PythonHandler mod_python.publisher"

Traceback (most recent call last):

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

File "/usr/lib/python2.3/site-packages/mod_python/publisher.py", line
173, in handler
result = apply(object, (), args)

TypeError: display() takes exactly 1 argument (0 given)

press the addition of the items:
Mod_python error: "PythonHandler mod_python.publisher"

Traceback (most recent call last):

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

File "/usr/lib/python2.3/site-packages/mod_python/publisher.py", line
173, in handler
result = apply(object, (), args)

File
"/home/hayward/public_html/Homework/Python_Executable_Publisher/form.py",
line 11, in addchocolate
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

OperationalError: (1054, "Unknown column 'artist' in 'field list'")

Thanks for the help

It's a while since I used mod_python, so this is a guess: The publisher
module finds function arguments in the POST input stream. Since your
form field is called "z_rating", publisher fails to find a "rating"
argument to pass to the function.

The second error message seems to imply that the database InventoryList
table doesn't have a column called "article".

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006 www.python.org/pycon/

Nov 6 '05 #3
Steve Holden wrote:
[...]

The second error message seems to imply that the database InventoryList
table doesn't have a column called "article".

regards
Steve


^article^artist^
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006 www.python.org/pycon/

Nov 6 '05 #4
In article <11**********************@g14g2000cwa.googlegroups .com>,
Little <co************@yahoo.com> wrote:
I have created the following database but the following errors occur
when trying to execute the code.

html source:
<html>
<body>
Click here to display information from Chocolate menu:
<form action ="form.py/display" method="POST">
<p>
Press to view the display
<input type="submit">
</p>
</form>
<br>
Please provide data for chocolate to be added:
<p>
<form action ="form.py/addchocolate" method="POST">
<p>
Name: <input type="text" name="z_Name" maxlength="30"><br>
Rating: <input type="text" name="z_rating" maxlength="3"><br>
Price : <input type="text" name="z_price" maxlength="5"><br>
<input type="submit">
</p>
</form>
</body>
</html>

form.py source

import MySQLdb

def addchocolate(z_Name, z_rating, z_price):

# make sure the user provided all the parameters
if not (z_Name and z_rating and z_price):
return "A required parameter is missing, \
please go back and correct the error"
db =
MySQLdb.connect(host="localhost",user="hayward",p asswd="hayward",db="hayward")
cursor = db.cursor()
cursor.execute(
"""INSERT INTO InventoryList (artist, title, rating) VALUES (%s,
%s, %s)""", (z_Name, z_rating, z_price) )

I hate to ask, but what happens when I enter "a, b, c);DROP DATABASE;" as
the entry for z_name? (Or some similar attempt to close the
SQL statement and start a new one). I think you want to google for "SQL
injection" and think about sanitising user input a bit.

--
Jim Segrave (je*@jes-2.demon.nl)

Nov 6 '05 #5
> I hate to ask, but what happens when I enter "a, b, c);DROP DATABASE;" as
the entry for z_name? (Or some similar attempt to close the
SQL statement and start a new one). I think you want to google for "SQL
injection" and think about sanitising user input a bit.


And using the parametrized form of cursor.execute() - which I guess is
easier to do. But you're right of course, too.

Regards,

Diez
Nov 7 '05 #6
On Sun, 06 Nov 2005 23:29:01 -0000, Jim Segrave wrote
In article <11**********************@g14g2000cwa.googlegroups .com>,
Little <co************@yahoo.com> wrote:
cursor.execute(
"""INSERT INTO InventoryList (artist, title, rating) VALUES (%s,
%s, %s)""", (z_Name, z_rating, z_price) )


I hate to ask, but what happens when I enter "a, b, c);DROP
DATABASE;" as the entry for z_name? (Or some similar attempt to
close the SQL statement and start a new one). I think you want to
google for "SQL injection" and think about sanitising user input a bit.


The OP is using execute() with a parameter tuple. This is the correct method
for executing a parametrized query, and it is immune to SQL injection as long
as the DB module implements parameter substitution in a sane way.

Best regards,

Carsten Haese.

Nov 7 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: wolf | last post by:
i would like to briefly share my experiences with installing mod_python on a w2000 box. i must say that i believe the installation process to be unnecessarily complicated by the simple fact that...
2
by: Robert J. Hansen | last post by:
I'm not entirely certain comp.lang.python is the proper newsgroup for mod_python questions, but "comp.lang.python.web" doesn't seem to exist, so... my apologies in advance if this is considered...
0
by: Python_it | last post by:
I'm going to work with mod_python. I install mod_python 3.2.2b for python 2.4. If i test my install with mptest.py see this link:...
6
by: Anthony L. | last post by:
I am writing a web application that is comparable to a content management system used in blogging. I really want to use Python after having done some evaluation coding using Python 2.3.5 with...
1
by: treelife | last post by:
I'm getting and internal server error when | run the following mod_python script. I am actually trying to run Django. Script: from mod_python import apache def handler(req):...
2
by: exhuma.twn | last post by:
Hi again, as soon as I try to make use of the "session" object inside a psp-template file, I get the following error: Mod_python error: "PythonHandler mod_python.publisher" Traceback (most...
5
by: m.banaouas | last post by:
Hi, bonjour, witch versions are suitable to use for apache & mod_python ? Can i install and use "Apache 2.2.3" & "mod_python 3.2.10" (most recent versions) without facing any known major...
2
by: m.banaouas | last post by:
I installed Apache 2.2.3 and mod_python 3.2.10 on WinXP plateform I configured mod_python via httpd.conf: LoadModule python_module modules/mod_python.so but my script folder configuration...
3
by: Michael | last post by:
Hey everyone, Is it possible to automatically insert headers/footers using mod_python? I will be not be using PSP's, so I cannot use the PSP/include solution. Furthermore, the header will be...
3
by: joe jacob | last post by:
I configured apache to execute python scripts using mod_python handler. I followed below mentioned steps to configure apache. 1. In http.conf I added <Directory...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.