【问题标题】:Python ldap3 LDAPSocketOpenError unable to send message, socket is not openPython ldap3 LDAPSocketOpenError 无法发送消息,套接字未打开
【发布时间】:2016-05-13 10:22:11
【问题描述】:

我正在用 Python 编码,ldap3 试图在 CentOS 上的 OpenLDAP 中创建用户。 我的本地开发机器正在运行 Windows 8 64 位。 下面是我的代码。

from ldap3 import Server, Connection, ALL

# define the server
s = Server('ldap://ldap.abcd.com:389', get_info=ALL)  

# define the connection
c = Connection(s, user='cn=Manager,dc=mydomain,dc=com', password='Super1')

# perform the Add operation
c.add('uid=user3,ou=People,dc=abcd,dc=com',['person','organizationalPerson','inetOrgPerson', 'posixGroup', 'top','shadowAccount'], {'givenName': 'user3firstname','sn': 'user3lastname', 'uidNumber' : 520,'gidNumber' : 521,'uid': 'user3','cn': 'user3user3lastname'})

# close the connection
c.unbind()

Server 和 Connection 类工作正常。我猜是因为如果我只运行这 2 个语句,它不会在下面生成错误。

LDAPSocketOpenError at /adminservice/users/
unable to send message, socket is not open
Request Method: GET
Request URL:    http://127.0.0.1:8000/adminservice/users/
Django Version: 1.8.4
Exception Type: LDAPSocketOpenError
Exception Value:    
unable to send message, socket is not open
Exception Location: C:\Python35\lib\site-packages\ldap3\strategy\base.py in send, line 299
Python Executable:  C:\Python35\python.exe
Python Version: 3.5.1
Python Path:    
['D:\\sourcecode\\idp',
 'D:\\sourcecode\\utils-drf-public-api',
 'C:\\Python26',
 'C:\\Python35\\python35.zip',
 'C:\\Python35\\DLLs',
 'C:\\Python35\\lib',
 'C:\\Python35',
 'C:\\Python35\\lib\\site-packages']
Server time:    Fri, 13 May 2016 17:02:08 +0700

【问题讨论】:

    标签: python windows centos ldap openldap


    【解决方案1】:

    您必须在添加用户之前绑定连接。在添加语句之前尝试c.bind()。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-11-20
      • 1970-01-01
      • 2018-06-05
      • 2015-05-17
      • 1970-01-01
      • 2019-07-04
      • 2016-02-28
      • 1970-01-01
      相关资源
      最近更新 更多