Use locale.getpreferredencoding() instead of assuming utf-8