LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   python-ldap: How to catch an error on binding? (http://www.linuxquestions.org/questions/programming-9/python-ldap-how-to-catch-an-error-on-binding-667532/)

eantoranz 09-04-2008 09:21 AM

python-ldap: How to catch an error on binding?
 
I'm just giving my first baby steps on python-ldap.

I have on purpose set up a connection that has to fail on binding... but I don't get to catch an error:

Code:

import ldap
import sys
ldapURI = "ldap://" + ldapServer + ":" + str(ldapPort)
print "LDAP URI: " + ldapURI
ldapConn = ldap.initialize(ldapURI)
try:
    ldapConn.bind(ldapLoginID, ldapLoginPasswd, ldap.AUTH_SIMPLE)
except:
    print "Caught an error!", sys.exc_info()
    sys.exit(-1)

When I run it, this is the output:
Code:

LDAP URI: ldap://10.0.1.251:389
And this is the network trace:
Code:

1        0.000000        10.0.1.31        10.0.1.251        TCP        55961 > ldap [SYN] Seq=0 Win=5840 Len=0 MSS=1460 TSV=22309611 TSER=0 WS=6
2        0.000318        10.0.1.251        10.0.1.31        TCP        ldap > 55961 [SYN, ACK] Seq=0 Ack=1 Win=5792 Len=0 MSS=1460 TSV=16565465 TSER=22309611 WS=5
3        0.000357        10.0.1.31        10.0.1.251        TCP        55961 > ldap [ACK] Seq=1 Ack=1 Win=5888 Len=0 TSV=22309612 TSER=16565465
4        0.000434        10.0.1.31        10.0.1.251        LDAP        bindRequest(1) "cn=root,dc=fake,dc=domain,dc=com" simple
5        0.000642        10.0.1.251        10.0.1.31        TCP        ldap > 55961 [ACK] Seq=1 Ack=49 Win=5792 Len=0 TSV=16565465 TSER=22309612
6        0.002085        10.0.1.251        10.0.1.31        LDAP        bindResponse(1) invalidCredentials
7        0.002144        10.0.1.31        10.0.1.251        TCP        55961 > ldap [ACK] Seq=49 Ack=15 Win=5888 Len=0 TSV=22309612 TSER=16565465
8        0.004096        10.0.1.31        10.0.1.251        LDAP        unbindRequest(2)
9        0.004144        10.0.1.31        10.0.1.251        TCP        55961 > ldap [FIN, ACK] Seq=56 Ack=15 Win=5888 Len=0 TSV=22309612 TSER=16565465
10        0.004172        10.0.1.31        10.0.1.251        TCP        55961 > ldap [RST, ACK] Seq=57 Ack=15 Win=5888 Len=0 TSV=22309612 TSER=16565465

How can I catch that problem in the code?


All times are GMT -5. The time now is 03:55 AM.