davidjbeiler
davidjbeiler

Reputation: 133

What does this mean: "unable to send message, socket is not open"?

I'm trying to connect to my ldap server, but it seems to be failing in someway or form:

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'])

Error on line 12: where attributes is, unable to send message, socket is not open

Upvotes: 0

Views: 4072

Answers (1)

dot.Py
dot.Py

Reputation: 5157

Try inserting c.bind() before the c.search() and after the Connection() statements.

According to LDAP3 Docs, you must bind() to establish a new authorization state in the server.

  • As specified in RFC4511 the Bind operation is the “authenticate” operation.

  • When you open a connection to an LDAP server you’re in an anonymous connection state. What this exactly means is defined by the server implementation, not by the protocol.

  • The bind() method will open the connection if not already open.

  • The Bind operation instead has nothing to do with the socket, but performs the user’s authentication.

Also you should use c.unbind() to close the connection.

Upvotes: 1

Related Questions