Python program fails on Windows but not on Linux -
the program below triggers unicodeencodeerror on windows 10 machine (running python 3.5.2) no error @ on linux machine (running python 3.3.2).
#!/usr/bin/python import logging str ="antonín dvořák" logging.basicconfig(filename='log.txt', level=logging.info) logging.info(str)
on linux, log file correctly contains:
info:root:antonín dvořák
on windows, following error:
any ideas on possible cause discrepancy?
instead of file name, pass stream encoding specified:
logging.basicconfig( stream=open('log.txt', 'w', encoding='utf-8'), level=logging.info )
as cause, it's trying open target file using current locale's encoding (cp1252, judging stack trace).
Comments
Post a Comment