if hasattr(sys, 'setdefaultencoding'): import locale lang, enc = locale.getdefaultlocale() sys.setdefaultencoding('utf-8')