You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I read the tutorial https://ldaptor.readthedocs.io/en/latest/quickstart.html and learned how to load LDAP entries from a static LDIF. Since I want to load contact from SQL database, I raised a question and get help from a kind response here #154
I tried the code below, and sent a query from Microsoft Outlook, but my program raised an error
import sys
from ldaptor.inmemory import ReadOnlyInMemoryLDAPEntry
from ldaptor.inmemory import fromLDIFFile
from ldaptor.interfaces import IConnectedLDAPEntry
from ldaptor.protocols.ldap.ldapserver import LDAPServer
from twisted.application import service
from twisted.internet.endpoints import serverFromString
from twisted.internet import reactor
from twisted.internet.protocol import ServerFactory
from twisted.python.components import registerAdapter
from twisted.python import log
class LDAPServerFactory(ServerFactory):
protocol = LDAPServer
def __init__(self, db_engine= None):
self.root = None
self.reload_tree()
def reload_tree(self):
"""
Building LDAP tree.
Call this method if you need to reload data from the database.
"""
com_tree = ReadOnlyInMemoryLDAPEntry('dc=org')
example_tree = com_tree.addChild('dc=example', {})
people_tree = example_tree.addChild('ou=people', {})
sales_tree = people_tree.addChild('ou=sales', {})
sales_tree.addChild('cn=bob', {
'cn': 'bob',
'gn': 'Bob',
'mail': 'bob@example.org',
'sn': 'Roberts'
})
self.root = com_tree
def buildProtocol(self, addr):
proto = self.protocol()
proto.debug = self.debug
proto.factory = self
return proto
if __name__ == '__main__':
log.startLogging(sys.stderr)
registerAdapter(lambda x: x.root, LDAPServerFactory, IConnectedLDAPEntry)
factory = LDAPServerFactory()
factory.debug = True
application = service.Application("ldaptor-server")
myService = service.IServiceCollection(application)
serverEndpointStr = "tcp:{0}".format(389)
e = serverFromString(reactor, serverEndpointStr)
d = e.listen(factory)
reactor.run()
The error information is
File "d:\code_python\LDAP\ldaptor\entryhelpers.py", line 172, in <listcomp>
if x.lower().startswith(filter.substrings[0].value.lower())
builtins.TypeError: startswith first arg must be str or a tuple of str, not bytes
here x is a plain string while the filter values are byte.
The text was updated successfully, but these errors were encountered:
I read the tutorial https://ldaptor.readthedocs.io/en/latest/quickstart.html and learned how to load LDAP entries from a static LDIF. Since I want to load contact from SQL database, I raised a question and get help from a kind response here #154
I tried the code below, and sent a query from Microsoft Outlook, but my program raised an error
The error information is
here x is a plain string while the filter values are byte.
The text was updated successfully, but these errors were encountered: