[mod_python] psp problem

Wouter van Marle wouter at squirrel-systems.com
Wed May 11 23:45:17 EDT 2005


On Wed, 2005-05-11 at 22:33 -0400, Jim Gallacher wrote:
> Wouter van Marle wrote:
> > On Wed, 2005-05-11 at 14:39 -0400, Jim Gallacher wrote:
> > 
> >>Wouter van Marle wrote:
> >>
> >>>Hi all,
> >>>
> >>>I've a problem using the psp functions.
> >>>What I am doing:
> >>>I've a psp page, using some in-line python code, in between <% and
> %> 
> >>>tags as per many examples. I however get all the time syntax errors
> when 
> >>>running this through the psp.PSP.run() function. I'm sure my python
> code 
> >>>as such is correct, so I'm at a loss here. Some code:
> >>>
> >>>page.psp:
> >>><html><head>
> >>><!-- rest of the header and so -->
> >>></head>
> >>><p> some text for the page </p>
> >>><%
> >>>for r in Results:
> >>>%>
> >>>I got the result <%=r%><br>
> >>><%
> >>># end indentation
> >>>%>
> >>>
> >>>then in my python program I have made a list Results, containing
> strings.
> >>>
> >>>page = psp.PSP(req, "page.psp")
> >>>page.run({"Results": Results})
> >>>
> >>>When running it like that, in my browser an error message appears
> giving 
> >>>a syntax error, pointing at the "for" in the loop.
> >>>
> >>>Now from the documentation I can not find anything that would
> forbid 
> >>>this. I haven't tried to set up a psp handler in apache, as I do
> not 
> >>>intend to use this as such. I want to be able to pass a list of
> results 
> >>>to the page, and then have the page fill itself, as smart template.
> The 
> >>>main code should be out of the page.
> >>>
> >>
> >>You found one of the warts in psp. Since your for loop contains no 
> >>further python statements, the parser gets confused. Try adding a
> single 
> >>comment at the beginning of your for loop:
> >>
> >><p> some text for the page </p>
> >><%
> >>for r in Results:
> >>     # begin indentation - comment fixes the syntax error
> >>%>
> >>I got the result <%=r%><br>
> >><%
> >># end indentation
> >>%>
> > 
> > 
> > Still the same problem, Jim.
> > I've also tried with comment before the 'for' statement, doesn't
> make
> > any difference :(
> > 
> > Wouter.
> > 
> 
> Actually, I was using the comment after the for statement to fix a
> slightly different problem. I've tested the snippet for the psp page
> you 
> posted before and it works for me. Perhaps you could post the actual 
> traceback?

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/python/search.py", line 75, in search
    page = psp.PSP(req, templatefilename)

  File "/usr/lib/python2.3/site-packages/mod_python/psp.py", line 111, in __init__
    self.load_from_file()

  File "/usr/lib/python2.3/site-packages/mod_python/psp.py", line 177, in load_from_file
    code = compile(source, filename, "exec")

  File "/var/www/html/templates/en/results.psp", line 20

    for r in SongResults:

    ^

SyntaxError: invalid syntax

Mind: I run this out of the main python script, though psp.PSP and then
page.run(). That may make a difference as well! I haven't tested it
as .psp page, which won't work as that way I can not pass the search
results to teh page.

Wouter.



More information about the Mod_python mailing list