This might help on systems where default encoding is not UTF-8 (and on Python 3). Thanks bacilla for the report. Backport of ed532a6a from master.