[mod_python] Re: PyChart into web site error

Graham Dumpleton grahamd at dscpl.com.au
Wed Oct 19 08:00:15 EDT 2005


On 19/10/2005, at 9:32 PM, G.M.Dall'Olio wrote:

>  Hi all, I'm getting this error from mod_python, when I try to use 
> PyChart to create a simple chart:
>
> Traceback (most recent call last):
>
>   File "/usr/lib/python2.4/site-packages/mod_python/apache.py", line 
> 299, in HandlerDispatch
>     result = object(req)
>
>   File "/usr/lib/python2.4/site-packages/mod_python/publisher.py", 
> line 136, in handler
>     result = util.apply_fs_data(object, req.form, req=req)
>
>   File "/usr/lib/python2.4/site-packages/mod_python/util.py", line 
> 361, in apply_fs_data
>     return object(**args)
>
>   File "/home/motif/public_html/Exp/PyChart/index.py", line 8, in home
>     chart = plot1.plot2()
>
>   File "/home/motif/public_html/Exp/PyChart/plot1.py", line 57, in 
> plot2
>     return ar.draw()
>
>   File "/usr/lib/python2.4/site-packages/pychart/area.py", line 188, 
> in draw
>     can = canvas.default_canvas()
>
>   File "/usr/lib/python2.4/site-packages/pychart/canvas.py", line 73, 
> in default_canvas
>     return init(None)
>
>   File "/usr/lib/python2.4/site-packages/pychart/canvas.py", line 58, 
> in init
>     can = pscanvas.T(fname)
>
>   File "/usr/lib/python2.4/site-packages/pychart/pscanvas.py", line 
> 25, in __init__
>     basecanvas.T.__init__(self)
>
>   File "/usr/lib/python2.4/site-packages/pychart/basecanvas.py", line 
> 70, in __init__
>     self.title = re.sub("(.*)\\.py$", "\\1", sys.argv[0])
>
> AttributeError: 'module' object has no attribute 'argv'
>
> I've searched with google and found that this topic has been already 
> addressed on this list, but still there is not solution. I've asked to 
> the author of the original post and he has resolved using spyce 
> instead of mod_python, but since I'm a newbie of mod_python, I would 
> like to continue with it.
>  Since the script works on the command line, probably it may be some 
> security setting in mod_python that restricts access to certain 
> modules, but I can't understand how to change this.
>  The python code in plot1.py is this:
>
>  from pychart import *
>  def plot2():
>
>          data = [["Jan", 10], ["Feb", 22], ["Mar", 30]]
>
>          ar = area.T(x_coord = category_coord.T(data, 0),
>          y_range = (0, None),
>          x_axis = axis.X(),
>          y_axis = axis.Y())
>          ar.add_plot(bar_plot.T(data = data, label = "Something"))
>
>          return ar.draw()
>
>  and the Directive in Apache configuration is this:
>
>  <Directory /home/motif/public_html/>
>      AllowOverride FileInfo
>      AddHandler mod_python .py
>      PythonHandler mod_python.publisher
>      PythonDebug On
>  </Directory>
>
>  It's about a month that I'm trying to resolve this... Can someone 
> give me some hints? Why mod_python requires sys.argv? Is this a 
> problem only of italian peoples? ;)

It isn't mod_python that requires sys.argv, it is pychart that is the 
problem based
on the traceback you provide. Ie., pychart has:

   self.title = re.sub("(.*)\\.py$", "\\1", sys.argv[0])

In short, pychart is written so as it can only work on the command line.

As a work around, can only suggest you create a special module that you 
import
using the PythonImport directive into the specific interpreter you are 
running
your mod_python code in, with that module containing:

   import sys
   sys.argv = ['mod_python']

Ie., dummy up a value for sys.argv.

Graham





More information about the Mod_python mailing list