- unicode exception handling on Jenkins error
- Laszlo Sitzer
- python, unicode, exception
Here is the exception:
The problem is that the exception comes from the jenkins module, which uses str() on the text returned from the web server, which apparently has a unicode '\xa0' character in it. (Unicode a0 is a non-breaking space)
I'd like to print out the text returned from the server, but I don't know how to query the exception for it, without the server trying to convert the text using the str() function.
If the default encoding for python is 'utf-8', instead of ascii, then things work better. I was able to work around this by doing:
but that is apparently an unnapproved way of handling this. The reload is required because the attribute 'setdefaultencoding' is used during sys import, but then deleted before the module becomes active.
Another possible solution is putting this at the top of the file:
OK - that doesn't work.
Another method to do this would be to make a safe_str_and_exit() which should only be called on an error path.
This would do the reload(sys) and sys.setdefaultencoding('utf8'), but only at error time, so that ftc doesn't have to suffer the overhead of these operations in the non-error case.
Fixed with commit 600c12ff - using the safe_str_and_exit routine