473,387 Members | 1,520 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,387 software developers and data experts.

lxml + mod_python: cannot unmarshal code objects in restricted execution mode

Hello everyone,

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, 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, 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

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,
anyone?
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)

So, I would be grateful for any suggestions how to get rid of this.
I'd really like to use lxml. Maybe I should initialize the xslt
processor in somehow other way?

Thanks in advance,
Dmitri

Sep 13 '07 #1
3 2524
Dmitri Fedoruk wrote:
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,
anyone?
Sure, lxml.etree can parse from file-like objects. Just hand in the result of
urlopen().

Apart from that, I saw that you found your way to the lxml mailing list, I'll
respond over there.

Stefan
Sep 13 '07 #2
On Sep 13, 5:05 pm, Dmitri Fedoruk <dfedo...@gmail.comwrote:
So, my configuration is the following:
Python 2.5.1
Server version: Apache/2.2.4 (FreeBSD)
mod_python-3.3.1
update:
lxml-1.3.4
libxslt-1.1.21
libxml2-2.6.29
Sep 13 '07 #3
On Sep 14, 3:04 am, Graham Dumpleton <Graham.Dumple...@gmail.com>
wrote:
Try forcing mod_python to run your code in the first interpreter
instance created by Python.
PythonInterpreter main_interpreter
Thank you very much, that solved the problem! A more detailed
discussion can also be found in the lxml-dev mailing list (
http://comments.gmane.org/gmane.comp...xml.devel/2942 )

Dmitri

Sep 14 '07 #4

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

Similar topics

0
by: David Connell | last post by:
I'm porting a mod_python / XML app that has been running in Apache 1.3 and I am running into trouble with Apache 2.0. Specifically, I'm getting a restricted execution mode error when I import the...
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...
0
by: Denis S. Otkidach | last post by:
When I execute python code from C++ application with PyEval_EvalCode and this code contains imports of other modules then I got the error "RuntimeError: cannot unmarshal code objects in restricted...
2
by: Arso - Italy | last post by:
Hi someone have already used eric3 for debugging code running on apache using mod_python ? After the execution of the patch for apache.py, how the debug is activated ? More thanks for any...
3
by: Rune Hansen | last post by:
I've posted this question on the mod_python mailing list but didn't get much response, so I thought I'd post it here. (My first attempt connected to an unrelated thread..sorry....
8
by: baustin75 | last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie only when debugging in php designer 2005 -------------------------------------------------------------------------------- ...
2
by: Srijit Kumar Bhadra | last post by:
I am new to lxml. I am interested to know the equivalent code using lxml (http://cheeseshop.python.org/pypi/lxml/1.1alpha). The code is taken from http://effbot.org/zone/xml-writer.htm from...
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: yinglcs | last post by:
Hi, I am trying to setup Apache with Trac which uses mod_python. I get the following error: assert have_pysqlite 0 And I have verify this via command line as well, that seem no problem....
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
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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,...

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.