LDAP Programming in Python
You probably are anxious now to run the program and see it in action. But first, you need to append the following code to call the main() function. It should go at the end of your script before you run it.
if __name__=='__main__':
main()
Now that you have inputted everything you need to run the Python program, save the source code in your editor and name the file ldap-test.py. Give it a run and test it out. If you don't see any output, it is probably because you didn't enter a valid LDAP server and/or who and cred, or because there simply is no existing search field on the server that matches the one we're using (in this case *ryan*).
We have only gotten our feet wet with how to use Python to write LDAP applications; you can do a lot more with python-ldap. You can find more python-ldap programming examples here.
For more information, check out the python-ldap documentation. A complete list of LDAP-related RFCs also are freely available on-line. If you are looking for a good book, consider LDAP Programming, Management, and Integration by Clayton Donely and LDAP: Programming Directory-Enabled Applications With Lightweight Directory Access Protocol by Tim Howes. These books use programming languages such as C/C++, Perl and Java for their code examples, but they still can be helpful for those who wish to code LDAP applications in Python. For an open-source implementation of LDAP, visit OpenLDAP's web site. There's also a developer's mailing list.
email: ambiod@sbcglobal.net
Today’s modular x86 servers are compute-centric, designed as a least common denominator to support a wide range of IT workloads. Those generic, virtualized IT workloads have much different resource optimization requirements than hyperscale and cloud applications. They have resulted in a “one size fits all” enterprise IT architecture that is not optimized for a specific set of IT workloads, and especially not emerging hyperscale workloads, such as web applications, big data, and object storage. In this report, you will learn how shifting the focus from traditional compute-centric IT architectures to an innovative disaggregated fabric-based architecture can optimize and scale your data center.
Sponsored by AMD
Built-in forensics, incident response, and security with Red Hat Enterprise Linux 6
Every security policy provides guidance and requirements for ensuring adequate protection of information and data, as well as high-level technical and administrative security requirements for a system in a given environment. Traditionally, providing security for a system focuses on the confidentiality of the information on it. However, protecting the data integrity and system and data availability is just as important. For example, when processing United States intelligence information, there are three attributes that require protection: confidentiality, integrity, and availability.
Learn more about catching the bad guy in this free white paper.
Sponsored by DLT Solutions
| Making Linux and Android Get Along (It's Not as Hard as It Sounds) | May 16, 2013 |
| Drupal Is a Framework: Why Everyone Needs to Understand This | May 15, 2013 |
| Home, My Backup Data Center | May 13, 2013 |
| Non-Linux FOSS: Seashore | May 10, 2013 |
| Trying to Tame the Tablet | May 08, 2013 |
| Dart: a New Web Programming Experience | May 07, 2013 |
- RSS Feeds
- New Products
- Making Linux and Android Get Along (It's Not as Hard as It Sounds)
- A Topic for Discussion - Open Source Feature-Richness?
- Drupal Is a Framework: Why Everyone Needs to Understand This
- Home, My Backup Data Center
- Python Programming for Beginners
- New Products
- Trying to Tame the Tablet
- Developer Poll
- Hey God - You may not be
3 hours 31 min ago - Reply to comment | Linux Journal
6 hours 4 min ago - Drupal is an Awesome CMS and a Crappy development framework
10 hours 43 min ago - IT industry leaders
13 hours 5 min ago - Reply to comment | Linux Journal
1 day 5 hours ago - Reply to comment | Linux Journal
1 day 8 hours ago - Reply to comment | Linux Journal
1 day 9 hours ago - great post
1 day 10 hours ago - Google Docs
1 day 10 hours ago - Reply to comment | Linux Journal
1 day 15 hours ago
Enter to Win an Adafruit Prototyping Pi Plate Kit for Raspberry Pi

It's Raspberry Pi month at Linux Journal. Each week in May, Adafruit will be giving away a Pi-related prize to a lucky, randomly drawn LJ reader. Winners will be announced weekly.
Fill out the fields below to enter to win this week's prize-- a Prototyping Pi Plate Kit for Raspberry Pi.
Congratulations to our winners so far:
- 5-8-13, Pi Starter Pack: Jack Davis
- 5-15-13, Pi Model B 512MB RAM: Patrick Dunn
- Next winner announced on 5-21-13!
Free Webinar: Linux Backup and Recovery
Most companies incorporate backup procedures for critical data, which can be restored quickly if a loss occurs. However, fewer companies are prepared for catastrophic system failures, in which they lose all data, the entire operating system, applications, settings, patches and more, reducing their system(s) to “bare metal.” After all, before data can be restored to a system, there must be a system to restore it to.
In this one hour webinar, learn how to enhance your existing backup strategies for better disaster recovery preparedness using Storix System Backup Administrator (SBAdmin), a highly flexible bare-metal recovery solution for UNIX and Linux systems.



Comments
thanks very much, I tried
thanks very much, I tried your code, it works well. But when I learn it from someother ldap server, i found that i cann't use the base="", I must write the concrete base if i want it to work. I really want to know what is the problem. I googled for this question, failed to get the reson, could you help me. I am really confused about this: why you said, in this example: base can be "". fortunately, the first example I tried with "" is also ok. I am a fresh bird, can someone help me?? That will be very appreciated.
I have just start to learn python
thanks for your share. i will have a try and learn.
I tried python for the first
I tried python for the first time and noticed that tabbing cripples the whole python language. Thanks and goodbye
Translation
Great!
Thanks.
We have translated your article in russian. If you have no objection - posted it on our website.
http://www.komtet.ru/info/python/ldap-v-python
Quite poorly written. The
Quite poorly written. The following is a much more practical explanation of getting started with python & ldap.
http://www.grotan.com/ldap/python-ldap-samples.html
It was good for the time
Keep in mind that in 2003, when this article was written, there were no other articles on LDAP programming in Python. So I think it was quite good for the time.
By the way, the linked code
By the way, the linked code is terrible. It's like someone tried to adapt another language for python.
The search code uses a permanent TRUE statement with a break.
Bad code
I was able to pick out the basics from this example, but the python code is terrible...
Re: LDAP Programming in Python
The code, for the most part, works for me. But I'm having trouble slicing the data portions out of the search result.
When grabbing 'description' (or any other attribute), I'm getting back:
string indices must be integers " entry[1]['description'][0] "
Re: LDAP Programming in Python
try this:
entyr[0][1]['description']
look for Python's Manual about List, Tuple and Dictionary!