There is also this trick, which turns environmental encoding errors into immediate exceptions rather than allowing them to enter your Python application:
import codecs
codecs.register_error('surrogateescape', codecs.strict_errors)
If you have a UTF-8 clean environment, this may not be a bad idea.