Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 850235
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T07:13:56+00:00 2026-05-15T07:13:56+00:00

I am trying to use python to query LDAP server, and it always returns

  • 0

I am trying to use python to query LDAP server, and it always returns me no result. and anyone help me find what wrong with my python code? it runs fine without excpetions, and it always has no result. i played around with the filter like “cn=partofmyname” but just no luck.
thanks for help

import ldap



try:
    l = ldap.open("server")
    l.protocol_version = ldap.VERSION3
    l.set_option(ldap.OPT_REFERRALS, 0)
    output =l.simple_bind("cn=username,cn=Users,dc=domian, dc=net",'password$R')
    print output
except ldap.LDAPError, e:
    print e

baseDN = "DC=domain,DC=net"
searchScope = ldap.SCOPE_SUBTREE
## retrieve all attributes - again adjust to your needs - see documentation for more options
retrieveAttributes = None

Filter = "(&(objectClass=user)(sAMAccountName=myaccount))"

try:
    ldap_result_id = l.search(baseDN, searchScope, Filter, retrieveAttributes)
    print ldap_result_id
    result_set = []
    while 1:
        result_type, result_data = l.result(ldap_result_id, 0)
        if len(result_data) == 0:
            print 'no reslut'
            break
        else:
            for i in range(len(result_set)):
                for entry in result_set[i]:
                    try:
                        name = entry[1]['cn'][0]
                        email = entry[1]['mail'][0]
                        phone = entry[1]['telephonenumber'][0]
                        desc = entry[1]['description'][0]
                        count = count + 1
                        print "%d.\nName: %s\nDescription: %s\nE-mail: %s\nPhone: %s\n" %\
                              (count, name, desc, email, phone)
                    except:
                        pass
                        ## here you don't have to append to a list
                        ## you could do whatever you want with the individual entry
            #if result_type == ldap.RES_SEARCH_ENTRY:
             # result_set.append(result_data)
            #  print result_set
except ldap.LDAPError, e:
    print e
l.unbind()
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T07:13:57+00:00Added an answer on May 15, 2026 at 7:13 am

    i found my problem.

    simple_bind("cn=username,cn=Users,dc=domian, dc=net",'password$R')
    

    should be

       simple_bind("domain/username",'password$R')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 530k
  • Answers 530k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Turns out it was because of the location of the… May 16, 2026 at 11:38 pm
  • Editorial Team
    Editorial Team added an answer It captures the entire Layer 2 frame. The layer 2… May 16, 2026 at 11:38 pm
  • Editorial Team
    Editorial Team added an answer Step #1: Make certain your INTERNET permission is in the… May 16, 2026 at 11:38 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I am trying to use parameter substitution with SQLite within Python for an IN
I'm trying to use Google's AJAX (JSON) Web Search API in Python. I'm stuck
I'm trying to screenscrape the first result of a Google search using Python and
I am trying to use the python 2.5 string formatting however I have run
I'm trying to use the python-daemon module. It supplies the daemon.DaemonContext class to properly
I'm quite new to python (I use python 3), and i'm trying to serialize
I m trying to use smtp class from Python 2.6.4 to send smtp email
I'm trying to find a tool and library to edit, write and read data
I'm trying to use a BULK INSERT statement to populate a large (17-million-row) table
I'm trying to use the dnspython library, and am a little confused by their

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.