Unicode exception in twisted

笑着哭i 提交于 2019-12-05 15:39:33

]It's not safe to log unicode with the Twisted logging system. Here's the minimal example that produces the exception you're seeing:

Python 2.6.4 (r264:75706, Dec  7 2009, 18:43:55)
[GCC 4.4.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from twisted.python import log
>>> import sys
>>> log.startLogging(sys.stdout)
2011-03-17 11:03:47-0400 [-] Log opened.
>>> log.msg(u'\N{SNOWMAN}')
2011-03-17 11:03:53-0400 [-] <unicode instance at 140508177816384 with str error Traceback (most recent call last):
      File "/usr/lib/python2.6/dist-packages/twisted/python/reflect.py", line 560, in safe_str
        return str(o)
    UnicodeEncodeError: 'ascii' codec can't encode character u'\u2603' in position 0: ordinal not in range(128)
    >
>>> 

So you need to find out what unicode is being logged and stop doing that, probably by encoding it in what ever way you want your log files to be encoded.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!