using python 2.6.5 and python-ldap 2.3.10, I have the following problem:
Under certain circumstances my application raises an ldap.LDAPError, or to be more specific, an ldap.INVALID_SYNTAX error. I catch this error and would like to process the message attached to it.
Now I can do something like this:
try:
some_ldap_function(*args,connection=con,**kwargs)
except ldap.INVALID_SYNTAX,e:
print e
This will give me
{'info': 'feeClass: value #0 invalid per syntax', 'desc': 'Invalid syntax'}
Now this is a dictrionary, and as far as I understand, I should be able to do something like
print e['info']
which is not the case. Instead I get a
TypeError Exception: sequence index must be integer, not ‘str’
What is wrong here?
You are misinterpreting what you are seeing
So printing e prints e.args[0], which is a string. That string looks like the repr of a dictionary, but that doesn’t mean that e is a dictionary (in fact, it should be clear that e can’t be a dictionary, since it must be an exception).