开发者

why all exception is being catched by ldap.SERVER_DOWN?

i have some code like below, i am trying to connect a server which is not existed to test timeout. after 120 sec, program quits with code 5. and 开发者_如何学Gomore, i disconnect from lan to test connect_error and it exits with code 5 again. why all exception is being catched by ldap.SERVER_DOWN? how can i test other exceptions?

try:
    ....

    l.simple_bind_s(user, password)

except ldap.CONNECT_ERROR, e:
    sys.exit(1)

except ldap.BUSY, e:
    sys.exit(2)

except ldap.OPT_NETWORK_TIMEOUT, e:
    sys.exit(3)

except ldap.TIMEOUT, e: 
    sys.exit(4)

except ldap.SERVER_DOWN, e:
    sys.exit(5)


Based on the python-ldap source, it looks like only a NonblockingLDAPObject can raise the exception ldap.TIMEOUT. You shouldn't have to handle it for a SimpleLDAPObject.


To test for BUSY you could bind to a working LDAP server, and then don't close (unbind) the connection. When you try and connect again the server should throw the BUSY error.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜