Hi,

I installed mod_wsgi module in my virtual machine and it works fine, I
received a "Hello world!" message from myapp.wsgi script.

Now I want to import some modules in the wsgi script and one of them
is the lxml module. The goal of my project is to return one XML file
as a result. It is only when I import the lxml module that mod_wsgi
crashed.

I did some research on the Internet and introduced the line
"WSGIApplicationGroup %{GLOBAL}" in the httpd.conf file, but that
didn't solve the problem. The error log has the following:


[Sun Mar 06 12:28:00 2011] [error] [client 10.249.0.102] mod_wsgi
(pid=12529): Target WSGI script '/var/www/html/wsgi-scripts/
myapp.wsgi' cannot be loaded as Python module.
[Sun Mar 06 12:28:00 2011] [error] [client 10.249.0.102] mod_wsgi
(pid=12529): Exception occurred processing WSGI script '/var/www/html/
wsgi-scripts/myapp.wsgi'.
[Sun Mar 06 12:28:00 2011] [error] Traceback (most recent call last):
[Sun Mar 06 12:28:00 2011] [error]   File "/var/www/html/wsgi-scripts/
myapp.wsgi", line 8, in <module>
[Sun Mar 06 12:28:00 2011] [error]     import lixo
[Sun Mar 06 12:28:00 2011] [error]   File "/var/www/html/wsgi-scripts/
lixo.py", line 2, in <module>
[Sun Mar 06 12:28:00 2011] [error]     from xml.etree.ElementTree
import Element, SubElement, tostring, XML
[Sun Mar 06 12:28:00 2011] [error] ImportError: No module named
xml.etree.ElementTree

As I thought that the problem was in python not knowing the location
of lxml, I added the following code to my myapp.wsgi file:


sys.path.insert(0, '/var/www/html/wsgi-scripts') # where I have the
python and wsgi files
sys.path.insert(1, '/usr/lib/python2.6/site-packages/') # Where the
python files are

However, I still get the same error in the log...
I'm going crazy with this error. Does anyone know what to do to make
mod_wsgi work with lxml?

Thank you,

Best regards,
Patrícia Sousa


PS: Some relevant files follows

httpd.conf:


LoadModule wsgi_module modules/mod_wsgi.so
AddHandler wsgi-script .wsgi .py
WSGIPythonHome /usr/bin/python2.6
WSGIApplicationGroup %{GLOBAL}

<Directory /var/www/html/wsgi-scripts>
  Options Indexes FollowSymLinks MultiViews
  Options +ExecCGI
  AllowOverride None
  Order allow,deny
  allow from all
</Directory>


myapp.wsgi:

#!/usr/bin/python2.6

import sys

sys.path.insert(0, '/var/www/html/wsgi-scripts')
sys.path.insert(1, '/usr/lib/python2.6/site-packages/')

import lixo # o ficheiro está na pasta /var/www/html/wsgi-scripts

def application(environ, start_response):
    status = '200 OK'
    output = 'Hello World!'

    response_headers = [('Content-type', 'text/plain'),
                        ('Content-Length', str(len(output)))]
    start_response(status, response_headers)

    print >> sys.stderr, 'sys.prefix = %s' % repr(sys.prefix)
    print >> sys.stderr, 'sys.path = %s' % repr(sys.path)

    return [output]


lixo.py:

#!/usr/bin/python2.6

# Even if i comment this next line the error appears on the second
import
from xml.etree.ElementTree import Element, SubElement, tostring, XML
from lxml import etree

xml2 = '<oai_dc:dc xmlns:dc="http://purl.org/dc/elements/1.1/";
xmlns:oai_dc="http://www.openarchives.org/OAI/2.0/
oai_dc/"><dc:identifier>foo:11</dc:identifier><dc:subject>fcrepo</
dc:subject><dc:subject>unittest</dc:subject><dc:description>bla</
dc:description><dc:description>A test object from the fcrepo unittest</
dc:description><dc:title>My First Test Object</dc:title></oai_dc:dc>'

def createHeaderXML():
  NS = 'http://www.w3.org/2001/XMLSchema-instance'
  TREE = '{%s}' % NS
  NSMAP = {None: NS}
  location_attribute = '{%s}schemaLocation' % NS
  root = etree.Element('OAI-PMH', attrib={location_attribute: 'http://
www.openarchives.org/OAI/2.0/OAI-PMHhttp://www.openarchives.org/OAI/2.0/OAI-PMH.xsd'})

  return root

def createNoResultXML():
  root = etree.Element('results')
  result = etree.SubElement(root, "result")
  result.text = "Without results"
  return root

cabe = createNoResultXML()
print etree.tostring(cabe, pretty_print=True)

-- 
You received this message because you are subscribed to the Google Groups 
"modwsgi" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/modwsgi?hl=en.

Reply via email to