I am coding in Python, ldap3 trying to create a user in OpenLDAP on CentOS. My local development machine is running Windows 8 64bit. Below is my code.
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()
The Server and Connection class is working ok. i guess because if i run only that 2 statements, it didn't generate an error below.
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
ldap3 usage is straightforward: you define a Server object and a Connection object. Then you issue commands to the connection. A server can have any number of active connections with the same or a different communication strategy. ldap3 specific exceptions are defined in the ldap3.
ldap3 is a pure Python LDAP 3 client library strictly conforming to RFC4510 and is released under the LGPL v3 open source license.
You must bind the connection before adding the user. Try c.bind()
before the add statement.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With