youfou / wxpy Goto Github PK
View Code? Open in Web Editor NEW微信机器人 / 可能是最优雅的微信个人号 API ✨✨
Home Page: http://wxpy.readthedocs.io
License: MIT License
微信机器人 / 可能是最优雅的微信个人号 API ✨✨
Home Page: http://wxpy.readthedocs.io
License: MIT License
groupWolf = robot.groups().search('狼群')[0]
robot.register(groupWolf)
到这总会报错,提示没有search方法,改成如下:
print(robot.groups())
输出结果为[]。
改成
robot.register() print(robot.groups())
才会有内容,求修复啊
怎么才能获取微信群的id?
hi
老哥, 看到你commit了一个新功能,是add friend by wxid
请问一下 这个是怎么用呢。貌似没有文档出来.......
Sharing 信息无法获取到url
Python 3.6.1
wxpy (0.3.9.2)
报错位置 https://github.com/bestony/wxpy/blob/master/wxpy/api/messages/message.py#L199
尝试发送图片消息的时候拿不到media_id
, 尝试了forward 方法 , 是正常起作用的,但这个方法没法持久化的起作用,就还挺不方便的
文档中说明要在额外的线程控制开关注册消息。
但我在代码中测试过程中,发现在单个线程中也能个进行开关注册。
想问问作者多线程中如何实现,谢谢
为什么没办法使用group的add_members和remove_members方法了。。里面username传微信昵称和微信号都不行。
下载二维码后无法扫描登陆,说是微信需要升级(已经最新了)。对手机版本要求那么高吗? @youfou
我开了5个微信,内存从开始的 110M,逐渐增长到 230M,而且还在持续增长,请问怎么解决
你好 代码如下
@bot.register()
def print_others(msg):
logging.info(msg)
if msg.type == "Note" and "刚刚把你添加到通讯录" in msg.text:
logging.info("add new friend: " + msg.chat.nick_name)
msg.chat.send_image('new_user.jpg')
msg.chat.accept()
return
我的微信机器人账号设置的加我好友时不需要验证,所以用户添加我到通讯录之后可以直接发消息给我,然后调用msg.chat.accept()时就有报错,报错信息如下
Fri, 28 Apr 2017 11:56:45 bot.py[line:330] ERROR
An error occurred in <function print_others at 0x7f6ea15c4730>.
Traceback (most recent call last):
File "/opt/python35/lib/python3.5/site-packages/wxpy/api/bot.py", line 326, in process
ret = config.func(msg)
File "ttsbot-prod.py", line 36, in print_others
bot.accept_friend(msg.chat)
File "/opt/python35/lib/python3.5/site-packages/wxpy/api/bot.py", line 253, in accept_friend
do()
File "/opt/python35/lib/python3.5/site-packages/wxpy/utils/misc.py", line 59, in wrapped
smart_map(check_response_body, ret)
File "/opt/python35/lib/python3.5/site-packages/wxpy/utils/misc.py", line 178, in smart_map
return func(i, *args, **kwargs)
File "/opt/python35/lib/python3.5/site-packages/wxpy/utils/misc.py", line 25, in check_response_body
raise ResponseError('ret: {}; err_msg: {}'.format(ret, err_msg))
wxpy.exceptions.ResponseError: ret: -1; err_msg:
"""
In [1]: ---------------------------------------------------------------------------
OSError Traceback (most recent call last)
/root/pyprj/wxbot_pya/run.py in ()
111 pos_send()
112 complex_reply()
--> 113 embed()
/root/.virtualenvs/wxpy_bot/lib/python3.5/site-packages/wxpy/utils/console.py in embed(local, banner, shell)
64 for _shell in shell, _ipython, _bpython, _python:
65 try:
---> 66 _shell(local=local, banner=banner)
67 except (TypeError, ImportError):
68 continue
/root/.virtualenvs/wxpy_bot/lib/python3.5/site-packages/wxpy/utils/console.py in _ipython(local, banner)
12 config=load_default_config()
13 )
---> 14 shell()
15
16
/root/.virtualenvs/wxpy_bot/lib/python3.5/site-packages/IPython/terminal/embed.py in call(self, header, local_ns, module, dummy, stack_depth, global_ns, compile_flags, **kw)
226 # our call and get the original caller's namespaces.
227 self.mainloop(local_ns, module, stack_depth=stack_depth,
--> 228 global_ns=global_ns, compile_flags=compile_flags)
229
230 self.banner2 = self.old_banner2
/root/.virtualenvs/wxpy_bot/lib/python3.5/site-packages/IPython/terminal/embed.py in mainloop(self, local_ns, module, stack_depth, display_banner, global_ns, compile_flags)
321
322 with self.builtin_trap, self.display_trap:
--> 323 self.interact()
324
325 # now, purge out the local namespace of IPython's hidden variables.
/root/.virtualenvs/wxpy_bot/lib/python3.5/site-packages/IPython/terminal/interactiveshell.py in interact(self, display_banner)
467
468 try:
--> 469 code = self.prompt_for_code()
470 except EOFError:
471 if (not self.confirm_exit) \
/root/.virtualenvs/wxpy_bot/lib/python3.5/site-packages/IPython/terminal/interactiveshell.py in prompt()
222 # This is very limited, and only accepts a single line.
223 def prompt():
--> 224 return cast_unicode_py2(input('In [%d]: ' % self.execution_count))
225 self.prompt_for_code = prompt
226 return
/root/.virtualenvs/wxpy_bot/lib/python3.5/site-packages/IPython/utils/py3compat.py in input(prompt)
150 # to forward requests to a frontend.
151 def input(prompt=''):
--> 152 return builtin_mod.input(prompt)
153
154 builtin_mod_name = "builtins"
OSError: [Errno 9] Bad file descriptor
"""
接收用户消息,然后添加好友的时候报错
Fri, 28 Apr 2017 11:56:45 bot.py[line:330] ERROR
An error occurred in <function print_others at 0x7f6ea15c4730>.
Traceback (most recent call last):
File "/opt/python35/lib/python3.5/site-packages/wxpy/api/bot.py", line 326, in process
ret = config.func(msg)
File "ttsbot-prod.py", line 36, in print_others
bot.accept_friend(msg.chat)
File "/opt/python35/lib/python3.5/site-packages/wxpy/api/bot.py", line 253, in accept_friend
do()
File "/opt/python35/lib/python3.5/site-packages/wxpy/utils/misc.py", line 59, in wrapped
smart_map(check_response_body, ret)
File "/opt/python35/lib/python3.5/site-packages/wxpy/utils/misc.py", line 178, in smart_map
return func(i, *args, **kwargs)
File "/opt/python35/lib/python3.5/site-packages/wxpy/utils/misc.py", line 25, in check_response_body
raise ResponseError('ret: {}; err_msg: {}'.format(ret, err_msg))
wxpy.exceptions.ResponseError: ret: -1; err_msg:
都不知道怎么修
大虾,首先为你创造了这么nb的项目点个赞哈……👍
然后我有个问题求教,就是登录之后返回验证码的问题
关于这个问题我尝试了以下两种方案
=================================================
1.控制台输出二维码,二维码太长了,超出屏幕了,分辨率也太低了,根本不行
2.保存二维码到指定路径,根本保存不出来,我去看了下二维码相关的代码,好像也没有保存逻辑呢
发送或者接收到消息后内存会增长,但是把 bot 对象销毁后,内存并没有得到释放,请问该如何处理
from wxpy import *
bot=Bot()
bot.create_group(['ken06o',],'hello')
-------------------------------------------错误代码----------------------------------------------
Traceback (most recent call last):
File "D:/app/math/add_friend.py", line 3, in
bot.create_group(['ken06o',],'hello')
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\site-packages\wxpy\api\bot.py", line 365, in create_group
raise Exception('Failed to create group:\n{}'.format(pformat(ret)))
Exception: Failed to create group:
{'BaseResponse': {'ErrMsg': '请求成功',
'RawMsg': '\n'
'1\n'
'\n'
'\n'
'30\n'
'<Title></Title>\n'
'4\n'
'0\n'
'0\n'
'\n'
'\n'
'\n',
'Ret': 0},
'BlackList': '',
'ChatRoomName': '',
'MemberCount': 0,
'MemberList': [],
'PYInitial': '',
'QuanPin': '',
'Topic': ''}
进程已结束,退出代码1
试用文档中的例子:
@bot.register(msg_types=CARD) def reply_text(msg): msg.chat.send_raw_msg(msg.raw['MsgType'], msg.raw['Content'])
报错信息如下:
2017-05-02 23:23:07,260 root CRITICAL UNCAUGHT EXCEPTION:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/code.py", line 91, in runcode
exec(code, self.locals)
File "", line 1, in
File "/Users/rxu/dev/wxpy-master/wxpy/api/chats/chat.py", line 29, in wrapped
kwargs_, attrs_ = func(self, *args, **kwargs)
File "/Users/rxu/dev/wxpy-master/wxpy/api/chats/chat.py", line 229, in send_raw_msg
req = BaseRequest(self.bot, uri=uri)
File "/Users/rxu/dev/wxpy-master/wxpy/utils/base_request.py", line 25, in init
self.url = self.bot.core.loginInfo['url'] + uri
TypeError: Can't convert 'NoneType' object to str implicitly
我想@机器人 移除 某用户,这样该怎么写?
我写了一半如下:
@bot.register(teamgroup)
def remove_msg(msg):
if msg.is_at:
if '移除' in msg.text.lower():
remove_members( ) <------这个“某用户”的参数该如何传递?
有时候 f1.set_remark_name('1234'),f1 是非自身的好友对象,报错 ResponseError: ret: 1205; err_msg:。
报错哎,请问怎么解决?
log:
Getting uuid of QR code.
Downloading QR code.
Please scan the QR code to log in.
Please press confirm on your phone.
Loading the contact, this may take a little while.
TERM environment variable not set.
Login successfully as Yang Hui
<Friend: Yang Hui>
Traceback (most recent call last):
File "/Users/yanghui/PycharmProjects/quantest/my_strategy/复盘/notices.py", line 23, in
if key_word in notices.title:
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pandas/core/generic.py", line 871, in contains
return key in self._info_axis
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pandas/indexes/base.py", line 1393, in contains
hash(key)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pandas/core/generic.py", line 831, in hash
' hashed'.format(self.class.name))
TypeError: 'DataFrame' objects are mutable, thus they cannot be hashed
Process finished with exit code 1
您好~
wxpy可以获取响应上下消息么?
因为 一般的注册事件都是单句响应,图灵的上下文响应是通过特殊的uid实现的。
那么但就微信消息本身,能否做到呢?
比如
User - 用户
Bot - wxpy 程序
User: 下载xxx.mp4
下载完成是否上传? Bot
User:上传
上传完成,地址是:xxx Bot
如何实现这样的注册事件呢?现在的情况似乎无法实现,我尝试了一下。
再次感谢~
如果还是需要扫码,可用性就没有那么强了啊
Traceback (most recent call last):
File "/path/lib/python3.5/site-packages/wxpy/api/bot.py", line 295, in process
ret = config.func(msg)
File "wxbot.py", line 23, in reply_pt_kill
if 'pt' in msg.text and 'kill' in msg.text:
TypeError: argument of type 'NoneType' is not iterable
如题,如果第二次不登陆,会卡在 Please scan the QR code to log in.
Getting uuid of QR code.
Downloading QR code.
Please scan the QR code to log in.
Please press confirm on your phone.
Loading the contact, this may take a little while.
Login successfully as xxx
Getting uuid of QR code.
Downloading QR code.
Please scan the QR code to log in.
Please press confirm on your phone.
LOG OUT!
Loading the contact, this may take a little while.
Login successfully as xxx
>>> bot.friends()
[]
>>> ```
我想实现只有@机器人的消息,机器人才出来回复,不然群里面任何人说话,机器人都跳出来,很乱啊,请问这个应该怎么设置?
我测试的时候,让好友把发送方拉黑,发送消息的时候,会出现多条发送日志。
连续多条日志:
至尊宝: 消息已发出,但被对方拒收了。 (Note)
最后,导致该微信号被限制:
再给其他正常好友发消息也出错:
发送消息过于频繁,等待对方接受你的好友请求后再发。 (Note)
不知道有没有什么设置?感谢!
大概需求就是把本地的音频,当作语音发出去?
nickname含有表情,UnicodeEncodeError: 'ascii' codec can't encode characters in position 6-10: ordinal not in range(128)
自己发给自己消息后,想再给自己一个反馈直接return 后抛出下面异常
wxpy.exceptions.ResponseError: ret: 1204; err_msg:
Using python3.5, and in Linux ENV.
In [43]: my_wife.send("test")
Out[43]: <ItchatReturnValue: {'MsgID': '8287475435897459665', 'LocalID': '14904491571103', 'BaseResponse': {'RawMsg': '请求成功', 'Ret': 0, 'ErrMsg': '请求成功'}}>
In [44]: Traceback (most recent call last):
File "/home/mint/.local/lib/python3.5/site-packages/itchat/components/login.py", line 240, in maintain_loop
msgList = produce_msg(self, msgList)
File "/home/mint/.local/lib/python3.5/site-packages/itchat/components/messages.py", line 61, in produce_msg
produce_group_chat(core, m)
File "/home/mint/.local/lib/python3.5/site-packages/itchat/components/messages.py", line 250, in produce_group_chat
atFlag = '@' + (chatroom['self']['DisplayName']
KeyError: 'self'
请问如何获取群二维码?我查看了 Group 对象的所以方法 并没有关于二维码的。谢谢!
环境:
Ubuntu 14.04, Python 3.4
wxpy 0.3.8,0.3.9 都有这个错误,0.3.6 无错误
代码:
from wxpy import embed, Bot
b1 = Bot()
embed()
错误:
Traceback (most recent call last):
File "test.py", line 1, in <module>
from wxpy import embed, Bot
File "/lib/python3.4/site-packages/wxpy/__init__.py", line 48, in <module>
from .api.bot import Bot
File "/lib/python3.4/site-packages/wxpy/api/bot.py", line 12, in <module>
from ..api.chats import Chat, Chats, Friend, Group, MP, User
File "/lib/python3.4/site-packages/wxpy/api/chats/__init__.py", line 1, in <module>
from .chat import Chat
File "/lib/python3.4/site-packages/wxpy/api/chats/chat.py", line 8, in <module>
from wxpy.utils import PuidMap, handle_response
File "/lib/python3.4/site-packages/wxpy/utils/__init__.py", line 5, in <module>
from .puid_map import PuidMap
File "/lib/python3.4/site-packages/wxpy/utils/puid_map.py", line 121
pickle.dump((*self.attr_dicts, self.captions), fp)
^
SyntaxError: can use starred expression only as assignment target
在 Bot 对象中增加一个新的接口,用于设置消息管道。
消息管道 (message_pipe):
今天进到服务器里看了一下,发现控制台没反应,我按了几次回车之后,消息突然乱发了,本来只有个人聊天的监听返回的消息发到群里,公众号里,只发了最近的几个有使用的。不知道是什么原因,我重启了服务,后面如果有的话我把报错的发出来。
小冰是个公众号,支持自动回复图片,声音,文字,所以我就想啊,能不能把非小冰发给我的消息全部自动发给小冰,然后提取小冰的回复,回复给非小冰对象,难点就是:有时候,你说一句,小冰有时要回复多句,而且不能分辨小冰的回复到底是回复哪一句的。。。不知道大神有没有法?
my_friend = robot.friends().search('游否', sex=MALE, city="深圳")[0]
robot.my_friend.send('Hello WeChat!')
此代码只能给一个好友发送信息,请问有什么方法,可以填加2个以上的好友,同时发送??
目前对于公众号类消息可以用Sharing来捕获,但是似乎仅限于单图文的。
如果对方发布的是多图文格式的,只能获得第一条的所有信息,而第二条及随后的所有信息全部被忽略。
不知道能否将多图文的信息转变为一个列表,这样可以逐一查看各自的内容。
我写了一个script,主要用来给微信群转发消息,还在测试,没有大规模用,但是log里总会有这样的报错,搜了一下有可能是被检测到是bot,所以没有正常response
http://stackoverflow.com/questions/33174804/python-requests-getting-connection-aborted-badstatusline-error
报错如下:
2017-05-13 19:59:50,616 requests.packages.urllib3.connectionpool WARNING Retrying (Retry(total=25, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', BadStatusLine('HTTP/1.1 0 -\r\n',))': /cgi-bin/mmwebwx-bin/synccheck?r=1494730776694&uin=342550695&skey=%40crypt_7a4288b7_8f6a503d952a2c85501b30509eefc69d&synckey=1_667084299%7C2_667084546%7C3_667084299%7C11_667084539%7C13_667084299%7C201_1494730774%7C203_1494730575%7C1000_1494723422%7C1001_1494723452%7C1004_1494344568&_=1494730776694&deviceid=e134616960240798&sid=sueBQ3Xfey7vC3co
你能确认是因为被检测到bot了吗?有什么办法吗?谢谢!
Will it support python 2?
大大您好,我今天在自己的服务器上尝试配置wxpy,做到第二步获取二维码时报错,
机器是ubuntu14.04 root用户登陆
屏幕输出如下
>>> robot = Robot()
Getting uuid of QR code.
Downloading QR code.
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.4/dist-packages/wxpy/wx.py", line 1024, in __init__
loginCallback=login_callback, exitCallback=logout_callback
File "/usr/local/lib/python3.4/dist-packages/itchat/components/register.py", line 35, in auto_login
loginCallback=loginCallback, exitCallback=exitCallback)
File "/usr/local/lib/python3.4/dist-packages/itchat/components/login.py", line 39, in login
picDir=picDir, qrCallback=qrCallback)
File "/usr/local/lib/python3.4/dist-packages/itchat/components/login.py", line 96, in get_QR
utils.print_qr(picDir)
File "/usr/local/lib/python3.4/dist-packages/itchat/utils.py", line 82, in print_qr
subprocess.call(['xdg-open', fileDir])
File "/usr/lib/python3.4/subprocess.py", line 537, in call
with Popen(*popenargs, **kwargs) as p:
File "/usr/lib/python3.4/subprocess.py", line 859, in __init__
restore_signals, start_new_session)
File "/usr/lib/python3.4/subprocess.py", line 1457, in _execute_child
raise child_exception_type(errno_num, err_msg)
FileNotFoundError: [Errno 2] No such file or directory: 'xdg-open'
请问是我遗漏了什么步骤吗
第三方应用读取 README.rst 文件时失败
api中只看到了添加好友和通过好友,如果好友数量超过5000是否就添加不上了?
bot.create_group(users=[baisong], topic='test2')
ResponseError: ret: 1101; err_msg:
报错……
friend = bot.friends()[6]
friend.get_avatar(save_path='/tmp/f.jpg')
the upper code will save the avatar to the filesystem, but i just want the url weixin server returned, how can i get it?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.