Skip to content

网络不好程序自动重启后推送异常 #2088

@nines97

Description

@nines97

1. Versions

What is your wechaty version?

Answer: wechaty-0.6.13

Which puppet are you using for wechaty? (hostie/puppeteer/padchat/...)

Answer: wechaty_puppet_hostie

What is your wechaty-puppet-XXX(padchat/puppeteer/) version?

Answer: wechaty_puppet_hostie-0.3.dev1

What os are you using

Answer: windows

2. Describe the bug

网络不好导致程序自动重启之后,我的推送连接丢失

3. Code

async def daily_push_contact(bot: MyBot):
    push_contact_list = dofile.get_data_list(dofile.contact_list)
    if len(push_contact_list) <= 0:
        return
    for contact_id in push_contact_list:
        contact = bot.Contact.load(contact_id)
        conversation: Union[Room, Contact] = contact
        await conversation.ready()
        await resource.picture(conversation)
        await resource.video(conversation)

async def daily_push_room(bot: MyBot):
    push_room_list = dofile.get_data_list(dofile.room_list)
    if len(push_room_list) <= 0:
        return
    for room_id in push_room_list:
        room = bot.Room.load(room_id)
        conversation: Union[Room, Contact] = room
        await conversation.ready()
        await resource.picture(conversation)
        await resource.video(conversation)

async def picture(conversation: Union[Room, Contact]):
    url = create_url("")
    file_box = FileBox.from_url(
        url["picture_url"], name='picture.jpg')
    await conversation.say(file_box)

async def video(conversation: Union[Room, Contact]):
    url = create_url("")
    file_box = FileBox.from_url(
        url["video_url"], name='video.mp4')
    await conversation.say(file_box)

async def main():
    global bot
    bot = MyBot()
    bot.on('scan', lambda status, qrcode, data: print('Scan QR Code to login: {}\nhttps://wechaty.js.org/qrcode/{}'.format(status, qrcode)))
    scheduler()
    await bot.start()

def scheduler():
    scheduler = AsyncIOScheduler()
    scheduler.add_job(daily_push_room, 'cron', minute="0", args=[bot])
    scheduler.add_job(daily_push_contact, 'cron', minute='30', args=[bot])
    scheduler.start()

def start():
    try:
        asyncio.run(main())
    except KeyboardInterrupt:
        pass

if __name__ == '__main__':
    start()

4. Full Output Logs

Show Logs
$ WECHATY_LOG=silly node yourbot.js

-> 2020-11-18 23:03:49,570 - Wechaty - ERROR - The network is not good, the bot will try to restart after 60 seconds.
ERROR:apscheduler.executors.default:Job "daily_push_contact (trigger: cron[minute='30'], next run at: 2020-11-18 23:30:00 CST)" raised an exception
Traceback (most recent call last):
  File "C:\Python39\lib\site-packages\grpclib\client.py", line 360, in recv_initial_metadata
    headers = await self._stream.recv_headers()
  File "C:\Python39\lib\site-packages\grpclib\protocol.py", line 342, in recv_headers
    await self.headers_received.wait()
  File "C:\Python39\lib\asyncio\locks.py", line 226, in wait
    await fut
asyncio.exceptions.CancelledError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Python39\lib\site-packages\apscheduler\executors\base_py3.py", line 29, in run_coroutine_job
    retval = await job.func(*job.args, **job.kwargs)
  File "D:\python-workspace\robot\vxbot\dailypush.py", line 29, in daily_push_contact
    await resource.video(conversation)
  File "D:\python-workspace\robot\vxbot\resource.py", line 32, in video
    await conversation.say(file_box)
  File "C:\Python39\lib\site-packages\wechaty\user\contact.py", line 228, in say
    msg_id = await self.puppet.message_send_file(
  File "C:\Python39\lib\site-packages\wechaty_puppet_hostie\puppet.py", line 344, in message_send_file
    response = await self.puppet_stub.message_send_file(
  File "C:\Python39\lib\site-packages\chatie_grpc\wechaty\__init__.py", line 1007, in message_send_file
    return await self._unary_unary(
  File "C:\Python39\lib\site-packages\betterproto\__init__.py", line 1124, in _unary_unary
    response = await stream.recv_message()
  File "C:\Python39\lib\site-packages\grpclib\client.py", line 408, in recv_message
    await self.recv_initial_metadata()
  File "C:\Python39\lib\site-packages\grpclib\client.py", line 380, in recv_initial_metadata
    self.initial_metadata = im
  File "C:\Python39\lib\site-packages\grpclib\utils.py", line 70, in __exit__
    raise self._error
grpclib.exceptions.StreamTerminatedError: Connection lost

ERROR:apscheduler.executors.default:Job "daily_push_room (trigger: cron[minute='0'], next run at: 2020-11-19 00:00:00 CST)" raised an exception

Traceback (most recent call last):
  File "C:\Python39\lib\site-packages\apscheduler\executors\base_py3.py", line 29, in run_coroutine_job
    retval = await job.func(*job.args, **job.kwargs)
  File "D:\python-workspace\robot\vxbot\dailypush.py", line 16, in daily_push_room
    await resource.picture(conversation)
  File "D:\python-workspace\robot\vxbot\resource.py", line 26, in picture
    await conversation.say(file_box)
  File "C:\Python39\lib\site-packages\wechaty\user\room.py", line 277, in say
    msg_id = await self.puppet.message_send_file(
  File "C:\Python39\lib\site-packages\wechaty_puppet_hostie\puppet.py", line 344, in message_send_file
    response = await self.puppet_stub.message_send_file(
  File "C:\Python39\lib\site-packages\chatie_grpc\wechaty\__init__.py", line 1007, in message_send_file
    return await self._unary_unary(
  File "C:\Python39\lib\site-packages\betterproto\__init__.py", line 1123, in _unary_unary
    await stream.send_message(request, end=True)
  File "C:\Python39\lib\site-packages\grpclib\client.py", line 241, in send_message
    await self.send_request()
  File "C:\Python39\lib\site-packages\grpclib\client.py", line 210, in send_request
    self.peer = self._stream.connection.get_peer()
  File "C:\Python39\lib\site-packages\grpclib\protocol.py", line 224, in get_peer
    return Peer(self._transport)
AttributeError: 'Connection' object has no attribute '_transport'

2020-11-18 23:03:49,628 - Wechaty - ERROR - internal error <'Connection' object has no attribute '_transport'>
2020-11-18 23:04:49,592 - Wechaty - INFO - restarting the bot ...
2020-11-18 23:04:49,593 - Wechaty - INFO - wechaty is stoping ...
2020-11-18 23:04:49,593 - Wechaty - INFO - stopping - stop puppet
2020-11-18 23:04:49,593 - HostiePuppet - INFO - stop()
2020-11-18 23:04:53,200 - Wechaty - INFO - stopping - unset puppet
2020-11-18 23:04:53,200 - Wechaty - INFO - wechaty has been stopped gracefully!
2020-11-18 23:04:53,204 - Wechaty - INFO - init_puppet_event_bridge() <<wechaty_puppet_hostie.puppet.HostiePuppet object at 0x0000013BBEEC00A0>>
2020-11-18 23:04:53,204 - Wechaty - INFO - initPuppetEventBridge() puppet.on(dong) (listenerCount:1) registering...
2020-11-18 23:04:53,204 - Wechaty - INFO - initPuppetEventBridge() puppet.on(error) (listenerCount:1) registering...
2020-11-18 23:04:53,204 - Wechaty - INFO - initPuppetEventBridge() puppet.on(heart-beat) (listenerCount:1) registering...
2020-11-18 23:04:53,204 - Wechaty - INFO - initPuppetEventBridge() puppet.on(ready) (listenerCount:1) registering...
2020-11-18 23:04:53,204 - Wechaty - INFO - receive <reset> event <%s>
2020-11-18 23:04:53,204 - Wechaty - INFO - initPuppetEventBridge() puppet.on(reset) (listenerCount:0) registering...
2020-11-18 23:04:53,204 - Wechaty - INFO - initPuppetEventBridge() puppet.on(friendship) (listenerCount:1) registering...
2020-11-18 23:04:53,204 - Wechaty - INFO - initPuppetEventBridge() puppet.on(login) (listenerCount:1) registering...
2020-11-18 23:04:53,204 - Wechaty - INFO - initPuppetEventBridge() puppet.on(logout) (listenerCount:1) registering...
2020-11-18 23:04:53,204 - Wechaty - INFO - initPuppetEventBridge() puppet.on(message) (listenerCount:1) registering...
2020-11-18 23:04:53,204 - Wechaty - INFO - initPuppetEventBridge() puppet.on(room-invite) (listenerCount:1) registering...
2020-11-18 23:04:53,205 - Wechaty - INFO - initPuppetEventBridge() puppet.on(room-join) (listenerCount:1) registering...
2020-11-18 23:04:53,205 - Wechaty - INFO - initPuppetEventBridge() puppet.on(room-leave) (listenerCount:1) registering...
2020-11-18 23:04:53,205 - Wechaty - INFO - initPuppetEventBridge() puppet.on(room-topic) (listenerCount:1) registering...
2020-11-18 23:04:53,205 - Wechaty - INFO - initPuppetEventBridge() puppet.on(scan) (listenerCount:1) registering...
2020-11-18 23:04:53,205 - Wechaty - INFO - starting puppet ...
2020-11-18 23:04:53,205 - HostiePuppet - INFO - init puppet
2020-11-18 23:04:53,205 - HostiePuppet - INFO - starting the puppet ...
2020-11-18 23:04:53,294 - HostiePuppet - INFO - puppet has started ...
2020-11-18 23:04:53,294 - HostiePuppet - INFO - listening the event from the puppet ...
2020-11-18 23:04:57,009 - wechaty.plugin - INFO - init the plugins ...
2020-11-18 23:04:57,010 - Wechaty - INFO - receive <login> event <EventLoginPayload(contact_id='wxid_58k2c8gfpjfd22')>

user: Contact <wxid_58k2c8gfpjfd22> <hjqx12369> has login

INFO:apscheduler.executors.default:Running job "daily_push_contact (trigger: cron[minute='30'], next run at: 2020-11-19 00:30:00 CST)" (scheduled at 2020-11-18 23:30:00+08:00)
ERROR:apscheduler.executors.default:Job "daily_push_contact (trigger: cron[minute='30'], next run at: 2020-11-19 00:30:00 CST)" raised an exception
Traceback (most recent call last):
  File "C:\Python39\lib\site-packages\apscheduler\executors\base_py3.py", line 29, in run_coroutine_job
    retval = await job.func(*job.args, **job.kwargs)
  File "D:\python-workspace\robot\vxbot\dailypush.py", line 28, in daily_push_contact
    await resource.picture(conversation)
  File "D:\python-workspace\robot\vxbot\resource.py", line 26, in picture
    await conversation.say(file_box)
  File "C:\Python39\lib\site-packages\wechaty\user\contact.py", line 228, in say
    msg_id = await self.puppet.message_send_file(
  File "C:\Python39\lib\site-packages\wechaty_puppet_hostie\puppet.py", line 344, in message_send_file
    response = await self.puppet_stub.message_send_file(
  File "C:\Python39\lib\site-packages\wechaty_puppet_hostie\puppet.py", line 188, in puppet_stub
    raise WechatyPuppetError('puppet_stub should not be none')
wechaty_puppet.exceptions.WechatyPuppetError: WechatyPuppetError('puppet_stub should not be none', None, None)

INFO:apscheduler.executors.default:Running job "daily_push_room (trigger: cron[minute='0'], next run at: 2020-11-19 01:00:00 CST)" (scheduled at 2020-11-19 00:00:00+08:00)
2020-11-19 00:00:00,019 - Room - INFO - Room say <<wechaty_puppet.file_box.file_box.FileBox object at 0x0000013BBEFB0EB0>, None>
ERROR:apscheduler.executors.default:Job "daily_push_room (trigger: cron[minute='0'], next run at: 2020-11-19 01:00:00 CST)" raised an exception
Traceback (most recent call last):
  File "C:\Python39\lib\site-packages\apscheduler\executors\base_py3.py", line 29, in run_coroutine_job
    retval = await job.func(*job.args, **job.kwargs)
  File "D:\python-workspace\robot\vxbot\dailypush.py", line 16, in daily_push_room
    await resource.picture(conversation)
  File "D:\python-workspace\robot\vxbot\resource.py", line 26, in picture
    await conversation.say(file_box)
  File "C:\Python39\lib\site-packages\wechaty\user\room.py", line 277, in say
    msg_id = await self.puppet.message_send_file(
  File "C:\Python39\lib\site-packages\wechaty_puppet_hostie\puppet.py", line 344, in message_send_file
    response = await self.puppet_stub.message_send_file(
  File "C:\Python39\lib\site-packages\wechaty_puppet_hostie\puppet.py", line 188, in puppet_stub
    raise WechatyPuppetError('puppet_stub should not be none')
wechaty_puppet.exceptions.WechatyPuppetError: WechatyPuppetError('puppet_stub should not be none', None, None)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions