473,698 Members | 2,086 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(xs lt, data, logger ):
try:
strXslt = urllib2.urlopen (xslt).read()
# i have to read the xslt url to the python string
except urllib2.HTTPErr or, e:
.......
except urllib2.URLErro r, e:
.............
try:
xslt_parser = etree.XMLParser ()
xslt_parser.res olvers.add( PrefixResolver( "XSLT") )

# and now I have to use the string; a more elegant solution,
anyone?
f = StringIO(strXsl t)
xslt_doc = etree.parse(f, xslt_parser)

# and here where the problem comes
transform = etree.XSLT(xslt _doc)

except Exception, exc:
logger.log(logg ing.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 2537
Dmitri Fedoruk wrote:
def extApplyXslt(xs lt, data, logger ):
try:
strXslt = urllib2.urlopen (xslt).read()
# i have to read the xslt url to the python string
except urllib2.HTTPErr or, e:
.......
except urllib2.URLErro r, e:
.............
try:
xslt_parser = etree.XMLParser ()
xslt_parser.res olvers.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.
PythonInterpret er main_interprete r
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
1226
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 ExpatPy piece. Any body know what, why or how to fix? Thanks!
1
2287
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 the installer itself seems to be buggy -- in my case, no combination of mod_python 3.0.4, 3.1.2b and python 2.2.3, 2.3.3 ever came to completion. rather, the installer would exit -- after an initial declaration of having successfully found python...
0
1303
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 execution mode". How can I switch into noraml (unrestricted) mode? Python 2.2.2, Linux. Actual code looks like the following: tstate = Py_NewInterpreter(); main_module = PyImport_AddModule("__main__");
2
2075
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 response. --
3
2187
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. Note-to-self:-must-get-more-coffee-before-posting-) It seems to me that for each path element in a URI a mod_python handler will be invoked. This applies to PythonAuthenHandler, PythonHeaderParserHandler and so on.
8
5473
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 -------------------------------------------------------------------------------- Hello, I have a very simple problem but cannot seem to figure it out. I have a very simple php script that sends a test email to myself. When I debug it in PHP designer, it works with no problems, I get the test email. If
2
2494
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 elementtree.SimpleXMLWriter import XMLWriter import sys w = XMLWriter(sys.stdout) html = w.start("html")
3
1800
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 dynamic; it won't be a static HTML page. In short, I've been looking for a page layout facility using mod_python.
3
1239
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. # python
0
8674
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8604
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8895
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7728
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5860
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4369
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4619
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2330
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2001
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.