| 
    Adrian Immler 
    mod_python-maillist at uebergeek.de
        Thu Jun 2 08:47:36 EDT 2005 
 hello !
i have following
def test(req):
  import matplotlib
  matplotlib.use('Agg')
  from matplotlib.backends.backend_agg import FigureCanvasAgg as
FigureCanvas
  from matplotlib.figure import Figure
  fig = Figure()
  canvas = FigureCanvas(fig)
  ax = fig.add_subplot(111)
  ax.plot([1,2,3])
  ax.set_title('hi mom')
  ax.grid(True)
  ax.set_xlabel('time')
  ax.set_ylabel('volts')
  canvas.print_figure(sys.stdout)
#  canvas.print_figure(req)
when i use this function from the console i get png binary output that i
could redirect to a file. when i call this function within mod_python
Mod_python error: "PythonHandler mod_python.publisher"
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 "/www/uebergeek.de/htdocs/music/test.py", line 44, in test
    canvas.print_figure(sys.stdout)
  File
"/usr/lib/python2.4/site-packages/matplotlib/backends/backend_agg.py",
line 383, in print_figure
    basename, ext = os.path.splitext(filename)
  File "/usr/lib/python2.4/posixpath.py", line 92, in splitext
    i = p.rfind('.')
AttributeError: 'builtin_function_or_method' object has no attribute
'rfind'
so i tried to direct it directly to the browser with the line above where
not (sys.stdout) but (req) is, but that produces this error:
Mod_python error: "PythonHandler mod_python.publisher"
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 "/www/uebergeek.de/htdocs/music/test.py", line 45, in test
    canvas.print_figure(req)
  File
"/usr/lib/python2.4/site-packages/matplotlib/backends/backend_agg.py",
line 383, in print_figure
    basename, ext = os.path.splitext(filename)
  File "/usr/lib/python2.4/posixpath.py", line 92, in splitext
    i = p.rfind('.')
AttributeError: 'mp_request' object has no attribute 'rfind'
so it is nearly the same error. now my question is:
how can i create a png file with matplotlib and send it to the client
without saving the file to harddisk and send that one.
thanks in advance !
p.s. yes i know that the content_type('image/png') is missing in the
above example ...
    
  |