I've a problem during exception-handling with the imapclient-library.
I tried to handle the LoginError like this:
source = IMAPClient(host=args.source_server, port=args.source_port, ssl=not args.source_no_ssl)
try:
print('Login source...'.format(args.source_user), end='', flush=False)
source.login(args.source_user, args.source_pass)
print('OK')
except exceptions.LoginError as e:
print('ERROR: {}'.format(e))
exit()
In case of exception i've got this:
Login source...ERROR: b'Invalid login'
I think The problem is, that format
is calling the __str__()
-method of the Exception-object and do not try to decode.
So the main question is who can i convert this string
"b'Invalid login'"
to a normal bytes-object like this?
b'Invalid login'
edit 1
@lenik
If i use e.message.decode()
like this:
try:
print('Login source...'.format(args.source_user), end='', flush=False)
source.login(args.source_user, args.source_pass)
print('OK')
except exceptions.LoginError as e:
print('ERROR: {}'.format(e.message.decode()))
exit()
I've got an AttributeError:
AttributeError: 'LoginError' object has no attribute 'message'
edit 2
@snakecharmerb
try:
print('Login source...'.format(args.source_user), end='', flush=False)
source.login(args.source_user, args.source_pass)
print('OK')
except exceptions.LoginError as e:
print('ERROR: {}'.format(e.args[0].decode()))
exit()
AttributeError: 'str' object has no attribute 'decode'