#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    2
    Rep Power
    0

    LDAP Search - Strip Out Result


    I want to query LDAP and get it to return an email address for a given UID. Here's the code I currently have:

    Code:
    #!/usr/bin/env python
    
    import ldap
    
    # Stage 5 - connect to LDAP
    ldap_conn = ldap.initialize("ldaps://address_taken_out")
    
    result = ldap_conn.search_s("ou=xx,dc=xx,dc=xx,dc=xx,dc=xx",
                                ldap.SCOPE_SUBTREE, 'uidnumber=73267', ['mail'])
    
    print result
    It works fine, but the result printed is:

    Code:
    [('uid=username,ou=people,ou=xx,dc=xx,dc=xx,dc=xx,dc=uxx', {'mail': ['username@emailaddress.com']})]
    I want to strip out everything and only be left with the email address, ready for use.

    What is the best way for doing something simple like this?

    Thanks!
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2007
    Location
    Joensuu, Finland
    Posts
    434
    Rep Power
    67
    Originally Posted by Kilamit
    What is the best way for doing something simple like this?
    The hackish way is of course:

    Code:
    print(result[0][1]['mail'][0])
    (Assuming the order of constituents is always the same.) The best way might require looking at the ldap moduleís contents. As itís not part of the standard library, I donít know where to look.
    My armada: openSUSE 13.1 (home desktop, home laptop), Crunchbang Linux 11 (mini laptop, work laptop), Ubuntu 14.04 LTS (server), Android 4.2.1 (tablet), Windows 7 Ultimate (testbed)
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    2
    Rep Power
    0
    Perfect, thank you!

    Is this considered an ok way to do this?

IMN logo majestic logo threadwatch logo seochat tools logo