Logentries Python示例返回UnicodeDecodeE

2024-06-16 09:08:52 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试设置一个“logentries”帐户来记录我的python开发事件。 但即使使用文档中最简单的测试,我也会遇到以下错误。有什么想法吗?你知道吗

Python 2.7.10 (default, May 23 2015, 09:40:32) [MSC v.1500 32 bit (Intel)] on wi
n32
Type "help", "copyright", "credits" or "license" for more information.
>>> from logentries import LogentriesHandler
>>> import logging
>>> log = logging.getLogger('logentries')
>>> log.setLevel(logging.INFO)
>>> log.addHandler(LogentriesHandler('xxxx-xxxx-xxxx-xxxx-xxxx'))
>>> log.info('teste')
LE: Starting Logentries Asynchronous Socket Appender
>>> Exception in thread Thread-1:
Traceback (most recent call last):
  File "C:\Python27\lib\threading.py", line 810, in __bootstrap_inner
    self.run()
  File "C:\Python27\lib\site-packages\logentries\utils.py", line 96, in run
    multiline = le_helpers.create_unicode(data).replace(
  File "C:\Python27\lib\site-packages\logentries\helpers.py", line 31, in create
_unicode
    return unicode(ch, 'utf-8')
UnicodeDecodeError: 'utf8' codec can't decode byte 0xe1 in position 59: invalid
continuation byte

Tags: runinpyimportloglibloggingline
1条回答
网友
1楼 · 发布于 2024-06-16 09:08:52

多亏了尼基塔的评论,我才发现问题所在。你知道吗

你知道吗助手.pylogentries中的lib不是为拉丁语言OS准备的,后者的时间戳标签有特殊的字母“á”。你知道吗

更换

unicode(ch,'utf8')

unicode(ch,'utf8','replace')

我成功了。你知道吗

相关问题 更多 >