这是什么意思:“无法发送消息,套接字未打开”?

时间:2017-04-07 17:28:38

标签: python python-3.x ldap

我正在尝试连接到我的ldap服务器,但它似乎以某种方式或形式失败:

import csv
from ldap3 import Server, Connection, ALL, NTLM, SUBTREE
import pandas as pd


server = Server('cybertest02.ad.arb.ca.gov', get_info=ALL)
c = Connection(server, user='myusername', password='mypassword')

c.search(search_base = 'o=test',
         search_filter = '(objectClass=inetOrgPerson)',
         search_scope = SUBTREE,
         attributes = ['cn', 'givenName'])

total_entries += len(c.response)
for entry in c.response:
    print(entry['dn'], entry['attributes'])

第12行出错:属性在哪里,无法发送消息,套接字未打开

1 个答案:

答案 0 :(得分:1)

尝试在c.bind()之前和c.search()语句之后插入Connection()

根据LDAP3 Docs,您必须bind()在服务器中建立新的授权状态。

  • 如RFC4511中所述,绑定操作是“身份验证”操作。

  • 当您打开与LDAP服务器的连接时,您处于匿名连接状态。这究竟意味着什么是由服务器实现定义的,而不是由协议定义的。

  • bind()方法会在尚未打开的情况下打开连接。

  • Bind操作改为与套接字无关,而是执行用户身份验证。

此外,您应该使用c.unbind()关闭连接。

相关问题