Add compatible imports for Python 3.
Python 3 doesn't have contextlib.nested.
Use force_text to obtain unicode values.
Exceptions don't have a 'message' attribute on Python 3.