mod_python and xml.dom.minidom

Graham Dumpleton Graham.Dumpleton at gmail.com
Wed May 13 20:53:20 EDT 2009


On May 12, 1:59 am, dpapathanasiou <denis.papathanas... at gmail.com>
wrote:
> For the record, and in case anyone else runs into this particular
> problem, here's how resolved it.
>
> My original xml_utils.py was written this way:
>
> from xml.dom import minidom
>
> def parse_item_attribute (item, attribute_name):
>     item_doc = minidom.parseString(item)
>     ...
>
> That version worked under the python interpreter, but failed under
> both mod_python andmod_wsgiapache modules with an error ("Parent
> module 'xml.dom' not loaded").
>
> I found that changing the import statement and the minidom reference
> within the function resolved the problem.
>
> I.e., after rewriting xml_utils.py this way, it works under both
> apache modules as well as in the python interpreter:
>
> import xml.dom.minidom
>
> def parse_item_attribute (item, attribute_name):
>     item_doc = xml.dom.minidom.parseString(item)
>     ...

FWIW, have just seen someone else raising an issue where something
caused problems unless a full package path was used. In that case it
was the 'email' package.

The common thing between these two packages is that they do funny
stuff with sys.modules as part of import.

For 'email' package it is implementing some sort of lazy loader and
aliasing thing to support old names. For 'xml.dom' it seems to replace
the current module with a C extension variant on the fly if the C
extension exists.

Were you getting this issue with xml.dom showing on first request all
the time, or only occasionally occurring? If the latter, were you
running things in a multithreaded configuration and was the server
being loaded with lots of concurrent requests?

For your particular Python installation, does the '_xmlplus' module
exist? Ie., can you import it as '_xmlplus' or 'xml.doc._xmlplus'?

Graham



More information about the Python-list mailing list