13 Sep 17:45
Re: lxml + mod_python: cannot unmarshal code objects in restricted execution mode
Stefan Behnel <stefan_ml <at> behnel.de>
2007-09-13 15:45:09 GMT
2007-09-13 15:45:09 GMT
Dmitri Fedoruk wrote:
> I'm developing a mod_python application that is based on XML\XSLT
> transforming.
>
> I used 4Suite libraries for that, but as the speed was unacceptable
> for me, I switched to lxml. Everything became much easier and 10 times
> faster
Thanks for sharing that. :)
> but I've encountered the subject problem.
>
> In brief - all my data and xslt are stored and transferred in UTF-8.
> With 4Suite everything was fine all the time. With lxml it works fine
> from the console, but inside mod_python it occasionaly dies, ~ one
> time out of three. Strange - the same code with the same data works or
> dies by its own means.
>
> As far as I have found, there was a similar problem with PyXML and
> encodings module, this is the problem with UTF, but there was no clear
> solution.
>
> So, my configuration is the following:
> Python 2.5.1
> Server version: Apache/2.2.4 (FreeBSD)
> mod_python-3.3.1
Looks like you forgot to mention the lxml version you are using.
> And the relevant parts of my code are these:
>
> def extApplyXslt(xslt, data, logger ):
> try:
> strXslt = urllib2.urlopen(xslt).read()
> # i have to read the xslt url to the python string
> except urllib2.HTTPError, e:
> .......
> except urllib2.URLError, e:
> .............
> try:
> xslt_parser = etree.XMLParser()
> xslt_parser.resolvers.add( PrefixResolver("XSLT") )
>
> # and now I have to use the string; a more elegant solution,
As I already mentioned on c.l.py, you can pass the result of urlopen()
directly into parse().
> f = StringIO(strXslt)
> xslt_doc = etree.parse(f, xslt_parser)
>
> # and here where the problem comes
> transform = etree.XSLT(xslt_doc)
>
> except Exception, exc:
> logger.log(logging.CRITICAL, exc.__str__() )
>
> try:
> result_tree = transform(data)
> return etree.tostring(result_tree, 'utf-8')
> except Exception, exc:
> print "xslt processing error!", exc.__str__()
> return ""
>
> It dies with the message 'cannot unmarshal code objects in restricted
> execution mode'. By profiling I detected the point where problem
> occurs:
> transform = etree.XSLT(xslt_doc)
Hmmm, I can't see where any "unmarshaling" should be taking place here -
definitely not in XSLT(). And I don't get why this should only happen once in
a while.
Can you figure out what is writing this message? The python interpreter or
mod_python?
Stefan
RSS Feed