Skip to content
This repository has been archived by the owner on Aug 23, 2020. It is now read-only.

运行时出现错误 #1

Closed
cnbillow opened this issue Aug 5, 2016 · 11 comments
Closed

运行时出现错误 #1

cnbillow opened this issue Aug 5, 2016 · 11 comments

Comments

@cnbillow
Copy link

cnbillow commented Aug 5, 2016

Traceback (most recent call last):
File "C:\Python27\lib\logging__init__.py", line 876, in emit
stream.write(fs % msg.encode("UTF-8"))
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe6 in position 44: ordinal
not in range(128)
Logged from file qqbot.py, line 290

@pandolia
Copy link
Owner

pandolia commented Aug 5, 2016

我这边运行都没问题的,收发中文消息都可以,可能是版本问题,我的是 Python2.7.10 ,您的版本是多少?

@pandolia
Copy link
Owner

pandolia commented Aug 5, 2016

line 290 是
QLogger.info('收到一条来自 %s%d(buddy%d) 的消息: <%s>' % pollResult)
可以运行到这一行那登录和收发消息都没问题了,您把这一行注释掉,改成
print "pollResult =", pollResult
看看能否正常输出,或者改为:
QLogger.info('收到一条消息')

@pandolia
Copy link
Owner

pandolia commented Aug 6, 2016

非常感谢 cnbillow 提供的错误信息,根据此信息,程序在 line 290 发生错误 :

QLogger.info('收到一条来自 %s%d(buddy%d) 的消息: <%s>' % pollResult)

初步怀疑可能在低版本 Python 中、或者是接收到某些特殊的消息时会导致 UnicodeDecodeError 错误。可能在这些情况下 QLogger.info 方法接收到的不是一个 str ,而是一个 unicode ,当 QLogger.info 方法内部对接收到的 unicode 进行解码时发生了错误。

但到目前为止我还未能复现此错误,我测试了很多稀奇古怪的消息,都可以正常运行。希望 cnbillow 还能提供更详细一点的错误信息,比方说把这一行改为:

print "pollResult =", pollResult
QLogger.info('收到一条消息')
for el in pollResult: print repr(el)

看看这些代码的输出信息是什么。

@pandolia
Copy link
Owner

pandolia commented Aug 8, 2016

由于一直未能复现此错误,本issue暂时关闭。此错误出现在第290行:

QLogger.info('收到一条来自 %s%d(buddy%d) 的消息: <%s>' % pollResult)

表明可成功收消息,只是打印消息出错了。建议遇到同样错误的朋友将本行改为:

QLogger.info('收到一条消息' + str(pollResult))

也希望您能将错误信息提供给我,帮助我改进本程序。

@pandolia pandolia closed this as completed Aug 8, 2016
@lvsenlin
Copy link

在linux下sys.getfilesystemencoding()获取到的是'ANSI_X3.4-1968',报错
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe4 in position 32: ordinal not in range(128)

如下代码:
File "/usr/lib/python2.7/site-packages/qqbot/qterm.py", line 109, in QTerm
command = command.decode(sys.getfilesystemencoding())

@pandolia
Copy link
Owner

这里改成 sys.stdin.encoding 或者 'utf8' 有用否?

@lvsenlin
Copy link

改了编译不了,好气!centos6.5 openssl升级了,python就不正常

@pandolia
Copy link
Owner

用 virtual env 装吧。

@pandolia
Copy link
Owner

#63

@lvsenlin
Copy link

2.1.4改出问题了,如下:
Traceback (most recent call last):
File "/usr/bin/qqbot", line 9, in
load_entry_point('qqbot==2.1.4', 'console_scripts', 'qqbot')()
File "/usr/lib/python2.7/site-packages/qqbot/qqbotcls.py", line 70, in RunBot
runBot((botCls or QQBot), qq, user)
File "/usr/lib/python2.7/site-packages/qqbot/qqbotcls.py", line 39, in runBot
conf = QConf(qq, user)
File "/usr/lib/python2.7/site-packages/qqbot/qconf.py", line 75, in init
self.readCmdLine()
File "/usr/lib/python2.7/site-packages/qqbot/qconf.py", line 84, in readCmdLine
help=STR2SYSTEMSTR('指定一个配置文件项目以导入设定。USER指的是配置文\n'
File "/usr/lib/python2.7/site-packages/qqbot/common.py", line 21, in STR2SYSTEMSTR
return s if PY3 else s.decode('utf8').encode(sys.stdin.encoding)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-15: ordinal not in range(128)

@lvsenlin
Copy link

这个问题已确定,要把操作系统改为utf-8,因为是命令行传入的是ascii,所以改代码无效。

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants