locale.getpreferredencoding() can in some cases return None. In that case use UTF-8