[mod_python] _ssl module not found with mod_python

Normand Savard nsavard at mapgears.com
Thu Jul 2 14:47:30 EDT 2009

I'm having an issue with the ssl module when mod_python is loaded.  I 
try to import ssl and got a "No module named _ssl" error (see below for 
the complete error output).  I have an Apache conf file and a Python 
script that is presented below.  When I use Python through the CGI, I'm 
able to import ssl with no error (see the Apache conf file and script 
used down below) as well as when I import the ssl module on the command 

Does someone have a hint of what maybe the problem?



Python mode:
Apache conf file:
LoadModule python_module libexec/mod_python.so

Alias /test "/home/nsavard/fgsmodpython2/www/htdocs/test"

<Directory /home/nsavard/fgsmodpython2/www/htdocs/test>
  AddHandler python-program .py
  PythonHandler http-proxy
  PythonDebug On

The script is:
import os
from mod_python import apache
import ssl

def handler(req):
  req.content_type = "text/plain"
  req.write("Proxy Hello World!")
  req.write('pythonhome   => %s' % os.getenv('PYTHONHOME'))
  req.write('pythonpath   => %s' % os.getenv('PYTHONPATH'))
  return apache.OK

The error is:


ProcessId:      30036
Interpreter:    'localhost'

ServerName:     'localhost'
DocumentRoot:   '/home/nsavard/fgsmodpython2/www/htdocs'

URI:            '/test/http-proxy.py'
Location:       None
Directory:      '/home/nsavard/fgsmodpython2/www/htdocs/test/'
Filename:       '/home/nsavard/fgsmodpython2/www/htdocs/test/http-proxy.py'
PathInfo:       ''

Phase:          'PythonHandler'
Handler:        'http-proxy'

Traceback (most recent call last):

  File "/home/nsavard/fgsmodpython2/lib/python2.6/site-packages/mod_python/importer.py", line 1537, in HandlerDispatch
    default=default_handler, arg=req, silent=hlist.silent)

  File "/home/nsavard/fgsmodpython2/lib/python2.6/site-packages/mod_python/importer.py", line 1202, in _process_target
    module = import_module(module_name, path=path)

  File "/home/nsavard/fgsmodpython2/lib/python2.6/site-packages/mod_python/importer.py", line 296, in import_module
    log, import_path)

  File "/home/nsavard/fgsmodpython2/lib/python2.6/site-packages/mod_python/importer.py", line 680, in import_module
    execfile(file, module.__dict__)

  File "/home/nsavard/fgsmodpython2/www/htdocs/test/http-proxy.py", line 6, in <module>
    import ssl

  File "/home/nsavard/fgsmodpython2/lib/python2.6/ssl.py", line 60, in <module>
    import _ssl             # if we can't import it, let the error propagate

ImportError: No module named _ssl


Accessed:       Thu Jul  2 14:31:48 2009
Generation:     0

_mp_dcbd4ef7bb04377d9cde8848becdadc4 {
  FileName:     '/home/nsavard/fgsmodpython2/www/htdocs/test/http-proxy.py'
  Instance:     1 [IMPORT]
  Generation:   0 [ERROR]
  Modified:     Tue Jun 30 16:12:23 2009

CGI mode
The Apache conf file:
Alias /test "/home/nsavard/fgsmodpython2/www/htdocs/test"

<Directory "/home/nsavard/fgsmodpython2/www/htdocs/test">
  AllowOverride None
  Options Indexes FollowSymLinks Multiviews ExecCGI
  Order allow,deny
  Allow from all

AddHandler cgi-script .py

The Python script is:
print "Content-type: text/html"
print "hello4"

import ssl

print "hello5"


More information about the Mod_python mailing list