Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

python2.7环境下中文微信昵称或者群组报编码错误 #10

Open
lyp2008001 opened this issue Jun 12, 2017 · 13 comments
Open

python2.7环境下中文微信昵称或者群组报编码错误 #10

lyp2008001 opened this issue Jun 12, 2017 · 13 comments

Comments

@lyp2008001
Copy link

group = bot.groups().search('游否')[0]
File "C:\Python27\lib\site-packages\wxpy\api\chats\groups.py", line 71, in search
return Groups(filter(match, self))
File "C:\Python27\lib\site-packages\wxpy\api\chats\groups.py", line 61, in match
if not match_name(group, keywords):
File "C:\Python27\lib\site-packages\wxpy\utils\misc.py", line 185, in match_name
if kw in str(getattr(chat, attr, '')).lower():
UnicodeDecodeError: 'utf8' codec can't decode byte 0xe6 in position 0: unexpected end of data

@bluedazzle
Copy link
Owner

方便提供下操作系统版本嘛?
@lyp2008001

@lyp2008001
Copy link
Author

@bluedazzle win10企业版

@leemon9527
Copy link

请问问题解决了吗。好像也碰到了这个问题

@bluedazzle
Copy link
Owner

看起来是 wxpy Windows 下编码的问题,会尽快修复。到时候可能需要重新安装 wxpy 库

bluedazzle pushed a commit to youfou/wxpy that referenced this issue Jun 14, 2017
Change-Id: I604187427d1084771fb1f4187fb25fce36dbff35
@leemon9527
Copy link

刚才研究了下
misc.py 中引入了future.builtins的str
if PY2:
from future.builtins import str
方法prepare_keywords中的参数如果使用python2.7的默认的str会导致判断isinstance(keyword,str)不成立

导致最后返回的map结果出错。

我暂时的解决办法是
在微信发送端的脚本中同样引入 from future.builtins import str ,然后在search的时候强制下类型转换
示例

from wxpy.compatible import PY2
if PY2:
from future.builtins import str

def main():
bot = Bot()

my = bot.friends().search(str('蓦然'))
listen(bot,receivers=my)

@bluedazzle
Copy link
Owner

嗯嗯,Windows 下系统编码不是 utf-8 所以 future.builtins 的 str 会出错。你可以先那样解决,我在 wxpy develop 分支修复了这个问题。你可以安装这个分支的 wxpy 试试 @leemon9527

@leemon9527
Copy link

@bluedazzle 刚才重新安装了wxpy的develop分支,好像还会报错
File "D:/Seafile/pyproject/PycharmTestProjects/wechat_msg_test/wx_msg.py", line 19, in
main()
File "D:/Seafile/pyproject/PycharmTestProjects/wechat_msg_test/wx_msg.py", line 14, in main
my = bot.friends().search('蓦然')
File "C:\Python27_10\lib\site-packages\wxpy-0.3.9.7-py2.7.egg\wxpy\api\chats\chats.py", line 50, in search
return Chats(filter(match, self), self.source)
File "C:\Python27_10\lib\site-packages\wxpy-0.3.9.7-py2.7.egg\wxpy\api\chats\chats.py", line 44, in match
if not match_name(chat, keywords):
File "C:\Python27_10\lib\site-packages\wxpy-0.3.9.7-py2.7.egg\wxpy\utils\misc.py", line 187, in match_name
if kw in '{0}'.format(getattr(chat, attr, '')).lower():
UnicodeDecodeError: 'utf8' codec can't decode byte 0xe8 in position 0: unexpected end of data

@bluedazzle
Copy link
Owner

ok,我再看看

@slyang-git
Copy link

group = bot.groups().search(u'游否')[0]

'游否' 前面 加一个 u --> u'游否'

解决了

@JustDoItQz
Copy link

Traceback (most recent call last):
File "C:\Program Files\JetBrains\PyCharm 2018.1.2\helpers\pydev\pydevd.py", line 1664, in
main()
File "C:\Program Files\JetBrains\PyCharm 2018.1.2\helpers\pydev\pydevd.py", line 1658, in main
globals = debugger.run(setup['file'], None, None, is_module)
File "C:\Program Files\JetBrains\PyCharm 2018.1.2\helpers\pydev\pydevd.py", line 1068, in run
pydev_imports.execfile(file, globals, locals) # execute the script
File "C:\Program Files\JetBrains\PyCharm 2018.1.2\helpers\pydev_pydev_imps_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "C:/developer/python_workplace/Python/wechat_sender_out.py", line 1, in
from wechat_sender import Sender
File "C:\developer\python_workplace\Python\wechat_sender.py", line 4, in
listen(bot)
NameError: name 'listen' is not defined

@JustDoItQz
Copy link

@bluedazzle 该怎么解决?

@JustDoItQz
Copy link

我下载的最新版

@bluedazzle
Copy link
Owner

@JustDoItQz 不要把你的文件名命名为 wechat_sender.py 换个名字

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

No branches or pull requests

5 participants