Python Forum
LDAP3 not return a list correctly?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
LDAP3 not return a list correctly?
#1
Hi,

I am using LDAP3 to retrieve every computer in my domain.

from ldap3 import Server, Connection, ALL
ad_computer_list = []


# Procedure to get AD computers
def get_ad_computers():
    search_domain = ('dc=uk,dc=co,dc=uk')
    search_user = ('CN=Lady DAP,OU=mc_u_service_,OU=mc,DC=uk,DC=co,DC=uk')
    search_password = ('password')
    # Set connection to LDAP Server
    ldap_server = Server('10.0.1.2', port = 636, use_ssl = True, get_info=ALL)
    server_query = Connection(ldap_server, search_user, search_password, auto_bind=True)
    #Check to see if you can connect on 636
    if server_query.bind() == True:
        #print(ldap_server.info)
        server_query.search(search_domain, '(objectclass=computer)')
        #server_query.search(search_domain, '(&(objectclass=computer)(name=*))')
        computer_names = server_query.entries
        print(server_query.entries)
    else:
        server_query.search(search_domain, '(objectclass=computer)')
        computer_name = server_query.entries
        print("389: ",computer_name)
It finds all the machines for me, but when I debug the list, it would seem it is not a proper list. It doesn't have a len value. I just want the computer name to compare to another list.

The error is

Unable to display children:Error resolving variables Traceback (most recent call last):
File "/Applications/PyCharm CE.app/Contents/plugins/python-ce/helpers/pydev/_pydevd_bundle/pydevd_comm.py", line 1208, in do_it
xml.write(pydevd_xml.var_to_xml(val, k, evaluate_full_value=evaluate_full_value))
File "/Applications/PyCharm CE.app/Contents/plugins/python-ce/helpers/pydev/_pydevd_bundle/pydevd_xml.py", line 369, in var_to_xml
elif hasattr(v, "__len__") and not is_string(v):
File "/Users/sm/Documents/_personal files/Folder/Python/GitHub/venv/lib/python3.8/site-packages/ldap3/abstract/entry.py", line 196, in __getattr__
raise LDAPCursorError(error_message)
ldap3.core.exceptions.LDAPCursorError: attribute '__len__' not found

What can I do to avoid this?

Best wishes

Michael
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How do I calculate a ratio from 2 numbers and return an equivalent list of about 1000 Pleiades 8 15,638 Jan-05-2024, 08:30 PM
Last Post: sgrey
  Ldap3 Python print(conn.entries) doesnt work ilknurg 15 5,747 Dec-28-2022, 11:22 AM
Last Post: shad
  Need to parse a list of boolean columns inside a list and return true values Python84 4 2,102 Jan-09-2022, 02:39 AM
Last Post: Python84
  How to invoke a function with return statement in list comprehension? maiya 4 2,826 Jul-17-2021, 04:30 PM
Last Post: maiya
  Regular expression: return string, not list Pavel_47 3 2,491 Jan-14-2021, 11:49 AM
Last Post: Pavel_47
  Function to return list of all the INDEX values of a defined ndarray? pjfarley3 2 1,961 Jul-10-2020, 04:51 AM
Last Post: pjfarley3
  Search a List of Dictionaries by Key-Value Pair; Return Dictionary/ies Containing KV dn237 19 6,696 May-29-2019, 02:27 AM
Last Post: heiner55
  List creation and return in Function leoahum 3 2,418 Mar-04-2019, 04:45 PM
Last Post: leoahum
  Function to return modified list Pjones006 2 3,418 Feb-06-2019, 10:57 PM
Last Post: Pjones006
  Making list empty after return in function dan789 10 5,751 Nov-24-2018, 11:54 PM
Last Post: micseydel

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020