No module named _md5

212 views
Skip to first unread message

e-gor

unread,
Jul 5, 2007, 2:59:28 PM7/5/07
to Django users
I have python 2.5.1, django report errors:

Mod_python error: "PythonHandler django.core.handlers.modpython"

Traceback (most recent call last):

File "/usr/local/lib/python2.5/site-packages/mod_python/apache.py",
line 193, in Dispatch
result = object(req)

File "/usr/local/lib/python2.5/site-packages/django/core/handlers/
modpython.py", line 177, in handler
return ModPythonHandler()(req)

File "/usr/local/lib/python2.5/site-packages/django/core/handlers/
modpython.py", line 145, in __call__
self.load_middleware()

File "/usr/local/lib/python2.5/site-packages/django/core/handlers/
base.py", line 31, in load_middleware
raise exceptions.ImproperlyConfigured, 'Error importing middleware
%s: "%s"' % (mw_module, e)

ImproperlyConfigured: Error importing middleware
django.middleware.common: "No module named _md5"

When i write import md5 from python command prompt i have no errors.

nick feng

unread,
Jul 5, 2007, 3:13:35 PM7/5/07
to django...@googlegroups.com
It' seems that the md5 is not a middleware, but you have write it in the setting.py file's middleware setting part.

e-gor

unread,
Jul 5, 2007, 3:46:24 PM7/5/07
to Django users
so what should i do? :) i'm newby :) there are no md5 module
requirements in the setting.py

Horst Gutmann

unread,
Jul 5, 2007, 4:59:00 PM7/5/07
to django...@googlegroups.com

Another idea: How have you installed Python? If you were using some kind
of package manager, check if there are some additional crypto-related
packages in the same repository :-)

- Horst

Roboto

unread,
Jul 6, 2007, 9:26:02 AM7/6/07
to Django users
i'm not great at this, but a shot in the dark - turn off mod_php

e-gor

unread,
Jul 7, 2007, 4:25:15 AM7/7/07
to Django users
Switching off mod_php doesn't help.

when i import module md5 from command prompt there are no errors:

# python
Python 2.5.1 (r251:54863, Jun 28 2007, 13:12:40)
[GCC 3.4.6 [FreeBSD] 20060305] on freebsd6
Type "help", "copyright", "credits" or "license" for more information.
>>> import md5
>>> import blahblah


Traceback (most recent call last):

File "<stdin>", line 1, in <module>
ImportError: No module named blahblah

Graham Dumpleton

unread,
Jul 7, 2007, 7:40:20 AM7/7/07
to Django users
On Jul 7, 6:25 pm, e-gor <sse...@gmail.com> wrote:
> Switching off mod_php doesn't help.
>
> when i import module md5 from command prompt there are no errors:
>
> # python
> Python 2.5.1 (r251:54863, Jun 28 2007, 13:12:40)
> [GCC 3.4.6 [FreeBSD] 20060305] on freebsd6
> Type "help", "copyright", "credits" or "license" for more information.>>> import md5
> >>> import blahblah
>
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> ImportError: No module named blahblah

Can you import 'hashlib' on the command line:

import hashlib

In Python 2.5 how the hash library modules is done was changed. This
has caused issues before:

http://www.modpython.org/pipermail/mod_python/2007-April/023508.html
http://www.modpython.org/pipermail/mod_python/2007-April/023512.html

A suitable answer wasn't found as it fixed itself when person
recompiled Apache.

My suspicion is that in recompiling Apache, Apache was then using the
same shared library version of something (probably SSL libraries) as
one of the Python hash modules was using. Previous to that it was
using different versions and that caused a problem when loading one of
the Python modules, thus resulting in it falling back to trying to
load _md5 when it shouldn't have. Loading _md5 would fail as in Python
2.5 it doesn't necessarily exist as hashlib modules replace it from
memory.

Note, in recompiling Apache it may be important to ensure that it
finds and uses system SSL libraries, otherwise it will use one from
its own source code and that is where the clash may arise because
Python will use the system one instead.

Graham

> On Jul 6, 4:26 pm, Roboto <robc...@gmail.com> wrote:
>
> > i'm not great at this, but a shot in the dark - turn off mod_php
>
> > On Jul 5, 2:59 pm, e-gor <sse...@gmail.com> wrote:
>
> > > I have python 2.5.1, django report errors:
>

> > >Mod_pythonerror: "PythonHandler django.core.handlers.modpython"

e-gor

unread,
Jul 10, 2007, 1:36:43 AM7/10/07
to Django users
Rebuilding apache doesn't help

# python
Python 2.5.1 (r251:54863, Jun 28 2007, 13:12:40)
[GCC 3.4.6 [FreeBSD] 20060305] on freebsd6
Type "help", "copyright", "credits" or "license" for more information.
>>> import md5

>>> import _md5


Traceback (most recent call last):
File "<stdin>", line 1, in <module>

ImportError: No module named _md5
>>> import hashlib
>>> import _hashlib


so i have error when importing _md5 and have no erroro when importing
md5. What it mean? :)

On Jul 7, 2:40 pm, Graham Dumpleton <Graham.Dumple...@gmail.com>
wrote:

Graham Dumpleton

unread,
Jul 10, 2007, 7:02:36 AM7/10/07
to Django users
On Jul 10, 3:36 pm, e-gor <sse...@gmail.com> wrote:
> Rebuilding apache doesn't help
>
> # python
> Python 2.5.1 (r251:54863, Jun 28 2007, 13:12:40)
> [GCC 3.4.6 [FreeBSD] 20060305] on freebsd6
> Type "help", "copyright", "credits" or "license" for more information.>>> import md5
> >>> import _md5
>
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> ImportError: No module named _md5
>
> >>> import hashlib
> >>> import _hashlib
>
> so i have error when importing _md5 and have no erroro when importing
> md5. What it mean? :)

Run:

ldd _hashlib.so

You'll need to go find _hashlib.so in the Python library directory.

As I said, what is possibly happening is that _hashlib.so has a
dependency on some shared library, probably the SSL libraries, and
this clashes with either the version used by Apache or which is
compiled into Apache.

Thus, also do:

ldd httpd

Ie., look at shared library dependencies for Apache executable.

If both show dependencies on same library but different versions you
will have a problem.

If no SSL library dependency for httpd, then it is using compiled in
version of SSL and you will have a problem.

In either case, you will need to rebuild Apache so that it uses the
same SSL shared library as Python _hashlib.so and as a dynamic library
dependency, not compiled in.

To absolutely confirm it is _hashlib.so, you can also write a basic
mod_python handler which does a direct import of _hashlib. If that
fails, then that module is definitely the cause.

Now if this thinking is correct, the reason that _md5 shows as the
problem, is that if Python can't import _hashlib in the hashlib
module, it will catch the exception and try and import _md5 instead,
but that doesn't exist in Python 2.5. Importing md5 works, because it
actually imports hashlib these days and not _md5 directly.

Graham

e-gor

unread,
Jul 12, 2007, 2:55:02 PM7/12/07
to Django users
# ldd _hashlib.so
_hashlib.so:
ldd: _hashlib.so: Shared object "_hashlib.so" not found, required by
"ldd"
_hashlib.so: exit status 1

So it's mean that _hashlib.so can't be loaded because it can't find
itself? It's strange

file _hashlib.so found at /usr/local/lib/python2.5/lib-dynload


with httpd all ok:

# ldd httpd
httpd:
libcrypt.so.3 => /lib/libcrypt.so.3 (0x280fe000)
libssl.so.4 => /usr/lib/libssl.so.4 (0x28116000)
libcrypto.so.4 => /lib/libcrypto.so.4 (0x28144000)
libexpat.so.4 => /usr/lib/libexpat.so.4 (0x28237000)
libc.so.6 => /lib/libc.so.6 (0x28255000)


On Jul 10, 2:02 pm, Graham Dumpleton <Graham.Dumple...@gmail.com>

Graham Dumpleton

unread,
Jul 12, 2007, 7:03:56 PM7/12/07
to Django users
On Jul 13, 4:55 am, e-gor <sse...@gmail.com> wrote:
> # ldd _hashlib.so
> _hashlib.so:
> ldd: _hashlib.so: Shared object "_hashlib.so" not found, required by
> "ldd"
> _hashlib.so: exit status 1
>
> So it's mean that _hashlib.so can't be loaded because it can't find
> itself? It's strange
>
> file _hashlib.so found at /usr/local/lib/python2.5/lib-dynload

You have to be in that directory or give absolute path name.

$ ldd /usr/lib/python2.5/lib-dynload/_hashlib.so
linux-gate.so.1 => (0xffffe000)
libssl.so.0.9.8 => /usr/lib/i686/cmov/libssl.so.0.9.8
(0xb7eae000)
libcrypto.so.0.9.8 => /usr/lib/i686/cmov/libcrypto.so.0.9.8
(0xb7d6c000)
libpthread.so.0 => /lib/tls/i686/cmov/libpthread.so.0
(0xb7d54000)
libc.so.6 => /lib/tls/i686/cmov/libc.so.6 (0xb7c13000)
libdl.so.2 => /lib/tls/i686/cmov/libdl.so.2 (0xb7c0f000)
libz.so.1 => /usr/lib/libz.so.1 (0xb7bfb000)
/lib/ld-linux.so.2 (0x80000000)

> with httpd all ok:
>
> # ldd httpd
> httpd:
> libcrypt.so.3 => /lib/libcrypt.so.3 (0x280fe000)
> libssl.so.4 => /usr/lib/libssl.so.4 (0x28116000)
> libcrypto.so.4 => /lib/libcrypto.so.4 (0x28144000)
> libexpat.so.4 => /usr/lib/libexpat.so.4 (0x28237000)
> libc.so.6 => /lib/libc.so.6 (0x28255000)

Are you using the standard OS version of Apache or your own version?
Make sure you are running this on the actual Apache version you are
using? What it is named may depend on your installation.

$ ldd /usr/sbin/apache2
linux-gate.so.1 => (0xffffe000)
libm.so.6 => /lib/tls/i686/cmov/libm.so.6 (0xb7f4e000)
libpcre.so.3 => /usr/lib/libpcre.so.3 (0xb7f2e000)
libaprutil-1.so.0 => /usr/lib/libaprutil-1.so.0 (0xb7f13000)
libldap_r.so.2 => /usr/lib/libldap_r.so.2 (0xb7edd000)
liblber.so.2 => /usr/lib/liblber.so.2 (0xb7ed0000)
libdb-4.4.so => /usr/lib/libdb-4.4.so (0xb7dd2000)
libpq.so.5 => /usr/lib/libpq.so.5 (0xb7db5000)
libsqlite3.so.0 => /usr/lib/libsqlite3.so.0 (0xb7d57000)
libexpat.so.1 => /usr/lib/libexpat.so.1 (0xb7d36000)
libapr-1.so.0 => /usr/lib/libapr-1.so.0 (0xb7d13000)
libuuid.so.1 => /lib/libuuid.so.1 (0xb7d10000)
librt.so.1 => /lib/tls/i686/cmov/librt.so.1 (0xb7d07000)
libcrypt.so.1 => /lib/tls/i686/cmov/libcrypt.so.1 (0xb7cd9000)
libpthread.so.0 => /lib/tls/i686/cmov/libpthread.so.0
(0xb7cc2000)
libdl.so.2 => /lib/tls/i686/cmov/libdl.so.2 (0xb7cbd000)
libc.so.6 => /lib/tls/i686/cmov/libc.so.6 (0xb7b7c000)
/lib/ld-linux.so.2 (0xb7f85000)
libresolv.so.2 => /lib/tls/i686/cmov/libresolv.so.2
(0xb7b69000)
libsasl2.so.2 => /usr/lib/libsasl2.so.2 (0xb7b52000)
libgnutls.so.13 => /usr/lib/libgnutls.so.13 (0xb7ae2000)
libssl.so.0.9.8 => /usr/lib/i686/cmov/libssl.so.0.9.8
(0xb7aa1000)
libcrypto.so.0.9.8 => /usr/lib/i686/cmov/libcrypto.so.0.9.8
(0xb795f000)
libkrb5.so.3 => /usr/lib/libkrb5.so.3 (0xb78e2000)
libcom_err.so.2 => /lib/libcom_err.so.2 (0xb78df000)
libtasn1.so.3 => /usr/lib/libtasn1.so.3 (0xb78ca000)
libz.so.1 => /usr/lib/libz.so.1 (0xb78b5000)
libgcrypt.so.11 => /usr/lib/libgcrypt.so.11 (0xb7864000)
libgpg-error.so.0 => /usr/lib/libgpg-error.so.0 (0xb7860000)
libk5crypto.so.3 => /usr/lib/libk5crypto.so.3 (0xb783b000)
libnsl.so.1 => /lib/tls/i686/cmov/libnsl.so.1 (0xb7824000)
libkrb5support.so.0 => /usr/lib/libkrb5support.so.0
(0xb781f000)

Did you try writing a basic mod_python handler which imports
'_hashlib' as suggested to see if that works? There errors messages
from that may give clues as to what the problem is.

Graham


Reply all
Reply to author
Forward
0 new messages