0

I have an URL "ldap://ldap.infonotary.com/dc=identity-ca,dc=infonotary,dc=com"

I wanted to get the LDAP DN and attributes from this URL using ldap3 library in python3. If I pass the whole URL to a class, I should be able to get DN, attributes from its functions. Also I should get hostname, extensions, port.

Sushruth N
  • 191
  • 2
  • 15
  • Possible duplicate of [Get protocol + host name from URL](https://stackoverflow.com/questions/9626535/get-protocol-host-name-from-url) (If you just need to get the URL, such as hostname and the path. You could easily iterate over each `path.split(',')` and do a `identifier, value = item.split('=')`) – Torxed Oct 24 '18 at 12:46
  • LDAP URL parsing is a bit special. So for various reasons one should use a decent module for that. And therefore the question is **not** a dup of the other question. – Michael Ströder Oct 24 '18 at 13:02
  • I agree, LDAP URL parsing is different from the HTTP URL parsing – Sushruth N Oct 25 '18 at 02:10

1 Answers1

1

Function ldap3.utils.uri.parse_uri() is your friend which returns a dictionary with the URL components:

>>> import ldap3.utils.uri    
>>> ldap3.utils.uri.parse_uri('ldap://ldap.infonotary.com/dc=identity-ca%2cdc=infonotary%2cdc=com')['base']
'dc=identity-ca,dc=infonotary,dc=com'
Michael Ströder
  • 1,248
  • 8
  • 12