[python-ldap] SERVER_DOWN: {'desc': "Can't contact LDAP server"} (no ssl)

Daniel Watrous dwmaillist at gmail.com
Thu Mar 12 19:43:15 CET 2015


I have the following class that creates an instance variable from
ldap.initialize. There is a long running instance that is part of a web
application. When first deployed, the app works as expected and connects to
the LDAP directory and can run queries.

class dao:

    host = 'ldap://ldap.company.com:123'
    scope = ldap.SCOPE_SUBTREE

    def __init__(self, base='o=hp.com'):
        self.base = base
        self.ldapconn = ldap.initialize(self.host)

    def execute_ldap_search(self, filter, attrs=None):
        """Execute an LDAP search based on the provided filter and
attributes"""
        return self.ldapconn.search_s(self.base, self.scope, filter, attrs)

After running for some time however, self.ldapconn appears to go bad and I
get this error:

Traceback (most recent call last):
File "/app/.python/lib/python2.7/site-packages/bottle.py", line 862, in
_handle
return route.call(**args)
File "/app/.python/lib/python2.7/site-packages/bottle.py", line 1732, in
wrapper
rv = callback(*a, **ka)
File "wsgi.py", line 22, in search_people
matching_people = persondao.find_by_last_first_comma(search, city, country)
File "/home/stackato/app/dao.py", line 83, in find_by_last_first_comma
return self.ldap_response_to_objects(self.execute_ldap_search(filter),
self.model_class)
File "/home/stackato/app/dao.py", line 27, in execute_ldap_search
return self.ldapconn.search_s(self.base, self.scope, filter, attrs)
File "/app/.python/lib/python2.7/site-packages/ldap/ldapobject.py", line
559, in search_s
return
self.search_ext_s(base,scope,filterstr,attrlist,attrsonly,None,None,timeout=self.timeout)
File "/app/.python/lib/python2.7/site-packages/ldap/ldapobject.py", line
552, in search_ext_s
msgid =
self.search_ext(base,scope,filterstr,attrlist,attrsonly,serverctrls,clientctrls,timeout,sizelimit)
File "/app/.python/lib/python2.7/site-packages/ldap/ldapobject.py", line
548, in search_ext
timeout,sizelimit,
File "/app/.python/lib/python2.7/site-packages/ldap/ldapobject.py", line
106, in _ldap_call
result = func(*args,**kwargs)
SERVER_DOWN: {'desc': "Can't contact LDAP server"}

Google provides lots of links for this error, but they all have to do with
SSL. I can connect just fine, but the connection goes bad.

How can I reconnect? Is there a better way to handle this?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ldap/attachments/20150312/a76309c6/attachment.html>


More information about the python-ldap mailing list