Skip to content

Instantly share code, notes, and snippets.

Created July 6, 2014 17:06
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save ssbarnea/876fd9e8ea7acc3697bb to your computer and use it in GitHub Desktop.
u = urlparse(url)
if u.scheme == 'ldaps':
use_ssl = True
use_ssl = False
if ":" in u.hostname:
u.hostname = u.hostname.split(":")[0]
if dn is None:
import netrc
netrc_config = netrc.netrc()
for h in netrc_config.hosts:
if h == u.hostname:
dn, account, secret = netrc_config.authenticators(h)
self.server = ldap3.Server(host=u.hostname, port=u.port, use_ssl=use_ssl)
self.conn = ldap3.Connection(self.server,
auto_bind = True,
client_strategy = ldap3.STRATEGY_SYNC,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment