[python-ldap] import _ldap: ImportError: Cannot load specified object

Zhang Huangbin zhbmaillistonly at gmail.com
Wed Aug 28 01:40:17 CEST 2013



On Wednesday, August 28, 2013 at 3:05 AM, Michael Ströder wrote:

> Is there any permissions problem?
> Does
> python -c "import ldap"
> also work when invoked as the web application's user?


You're right. I cannot import module as the Apache daemon user "www".

# chsh -s /bin/sh www
# su - www
$ python -c "import ldap"
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/local/lib/python2.7/site-packages/python_ldap-2.4.13-py2.7-openbsd-5.3-amd64.egg/ldap/__init__.py", line 22, in <module>
import _ldap
ImportError: Cannot load specified object



I try to trace it to see if there's any permission related issue, and i got it solved. Here's what i did:

1) Create a python file with only one line: "import ldap".
2) Trace it with command "ktrace" (it's an alternative for "strace" on Linux):  

# su -  www
$ ktrace -t + python 1.py    # <- Got error like before: "ImportError: Cannot load specified object"
$ kdump -f ktrace.out | grep -2 -i 'permission denied'
30863 python2.7 CALL open(0x16a25bfbf771,0<O_RDONLY>)
30863 python2.7 NAMI "/usr/local/lib/libsasl2.so.3.0"
30863 python2.7 RET open -1 errno 13 Permission denied


As you can see, it cannot load file "/usr/local/lib/libsasl2.so.3.0". I checked its permission:

-rwx------ 1 root bin 123670 Feb 26 2013 /usr/local/lib/libsasl2.so.3.0

Fix it:

# chmod +rx /usr/local/lib/libsasl2.so.3.0

And now my web application works.

Thanks very much for your help. :)


More information about the python-ldap mailing list