Fix UnicodeEncodeError

if fail to encode to utf8, unencoded charactor is written.