Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 如何使用python ldap中的搜索_Python 3.x_Search_Base_Python Ldap - Fatal编程技术网

Python 3.x 如何使用python ldap中的搜索

Python 3.x 如何使用python ldap中的搜索,python-3.x,search,base,python-ldap,Python 3.x,Search,Base,Python Ldap,我需要在python中执行以下命令: ldapsearch -H ldap://10.120.80.17:300 -x -LLL "uid=cich" 然后,我在bash中将其作为输出: dn: employeeNumber=621,ou=Internal,ou=People,o=NSN mail: name.surname@example.com objectClass: nsnEDPerson objectClass: inetorgperson objectClass: organiz

我需要在python中执行以下命令:

ldapsearch -H ldap://10.120.80.17:300 -x -LLL "uid=cich" 
然后,我在bash中将其作为输出:

dn: employeeNumber=621,ou=Internal,ou=People,o=NSN
mail: name.surname@example.com
objectClass: nsnEDPerson
objectClass: inetorgperson
objectClass: organizationalPerson
objectClass: person
objectClass: top
objectClass: dspswuser
objectClass: posixAccount
objectClass: shadowAccount
nsnSiteCode: 600906
gidNumber: 555
uid: cich
loginShell: /bin/bash
homeDirectory: /home/cich
nsnPrimaryEmailAddress: name.surname@example.com
gecos: surname name
employeeNumber: 6216
cn: surname name
uidNumber: 6216
这就是我试图通过使用python ldap库在python中执行的内容,但它不起作用,我在最后一行中得到了一个带有“result”的错误

import ldap

con = ldap.initialize('ldap://10.120.80.17:300')
ldap_base = "ou=Internal,ou=People,o=NSN"
query = "(uid=cich)"
result = con.search_s(ldap_base, ldap.SCOPE_SUBTREE, query)
我想我不明白我必须在ldap_库中放些什么,你能解释一下吗

lib中有一些文档:

  def search_ext(self,base,scope,filterstr=None,attrlist=None,attrsonly=0,serverctrls=None,clientctrls=None,timeout=-1,sizelimit=0):
    """
    search(base, scope [,filterstr='(objectClass=*)' [,attrlist=None [,attrsonly=0]]]) -> int
    search_s(base, scope [,filterstr='(objectClass=*)' [,attrlist=None [,attrsonly=0]]])
    search_st(base, scope [,filterstr='(objectClass=*)' [,attrlist=None [,attrsonly=0 [,timeout=-1]]]])
    search_ext(base,scope,[,filterstr='(objectClass=*)' [,attrlist=None [,attrsonly=0 [,serverctrls=None [,clientctrls=None [,timeout=-1 [,sizelimit=0]]]]]]])
    search_ext_s(base,scope,[,filterstr='(objectClass=*)' [,attrlist=None [,attrsonly=0 [,serverctrls=None [,clientctrls=None [,timeout=-1 [,sizelimit=0]]]]]]])

        Perform an LDAP search operation, with base as the DN of
        the entry at which to start the search, scope being one of
        SCOPE_BASE (to search the object itself), SCOPE_ONELEVEL
        (to search the object's immediate children), or SCOPE_SUBTREE
        (to search the object and all its descendants).

        filter is a string representation of the filter to
        apply in the search (see RFC 4515).

        Each result tuple is of the form (dn,entry), where dn is a
        string containing the DN (distinguished name) of the entry, and
        entry is a dictionary containing the attributes.
        Attributes types are used as string dictionary keys and attribute
        values are stored in a list as dictionary value.

        The DN in dn is extracted using the underlying ldap_get_dn(),
        which may raise an exception of the DN is malformed.

        If attrsonly is non-zero, the values of attrs will be
        meaningless (they are not transmitted in the result).

        The retrieved attributes can be limited with the attrlist
        parameter.  If attrlist is None, all the attributes of each
        entry are returned.

        serverctrls=None

        clientctrls=None

        The synchronous form with timeout, search_st() or search_ext_s(),
        will block for at most timeout seconds (or indefinitely if
        timeout is negative). A TIMEOUT exception is raised if no result is
        received within the time.

        The amount of search results retrieved can be limited with the
        sizelimit parameter if non-zero.
    """

参数
base
是搜索基,有时称为搜索根。它指定开始搜索的整个目录信息树(DIT)的子树。它的含义与ldapsearch工具的命令行选项
-b
相同。您的本地配置(文件)可能包含此配置的默认值

大多数情况下,您会为此选择LDAP服务器数据库的顶级条目。如果您的LDAP服务器授予对根DSE的读取权限,则您可以查询LDAP服务器上各种数据库的“命名上下文”,如下所示:

ldapsearch -H ldap://10.120.80.17:300 -x -LLL -b "" namingContexts

现在还不清楚您的Python脚本是否真的有问题,或者您只需要大致了解。