I wouldn’t call it a “solution” (at least, not unless you understand its problems and sign up for dealing with them):
The real solution is to always convert str<->unicode
explicitly, with explicit encoding. For I/O, you can set PYTHONIOENCODING
but then you need to somehow make sure it’s always set.