wechaty / python-wechaty

Python Wechaty is a Conversational RPA SDK for Chatbot Makers written in Python
https://wechaty.readthedocs.io/zh_CN/latest/
Apache License 2.0
1.62k stars 234 forks source link

Excetions: can not get message callback response #82

Open why2lyj opened 4 years ago

why2lyj commented 4 years ago
 Traceback (most recent call last):
   File "/usr/local/lib/python3.7/site-packages/apscheduler/executors/base_py3.py", line 29, in run_coroutine_job
     retval = await job.func(*job.args, **job.kwargs)
   File "/ding-dong-bot.py", line 199, in xxxx
     await conversation.say(file_box)
   File "/usr/local/lib/python3.7/site-packages/wechaty/user/room.py", line 266, in say
     file=some_thing
   File "/usr/local/lib/python3.7/site-packages/wechaty_puppet_hostie/puppet.py", line 322, in message_send_file
     filebox=file.to_json_str()
   File "/usr/local/lib/python3.7/site-packages/chatie_grpc/wechaty.py", line 886, in message_send_file
     "/wechaty.Puppet/MessageSendFile", request, MessageSendFileResponse,
   File "/usr/local/lib/python3.7/site-packages/betterproto/__init__.py", line 1124, in _unary_unary
     response = await stream.recv_message()
   File "/usr/local/lib/python3.7/site-packages/grpclib/client.py", line 387, in recv_message
     await self.recv_initial_metadata()
   File "/usr/local/lib/python3.7/site-packages/grpclib/client.py", line 355, in recv_initial_metadata
     self._raise_for_grpc_status(headers_map)
   File "/usr/local/lib/python3.7/site-packages/grpclib/client.py", line 316, in _raise_for_grpc_status
     raise GRPCError(status, message, details)
 grpclib.exceptions.GRPCError: (<Status.INTERNAL: 13>, 'can not get message callback response.', None)

I'm using scheduler to send pictures to a ChatRoom and got issue above code like followed:

 room = bot.Room.load("xxxxxxxxx@chatroom")
 conversation: Union[Room, Contact] = room
 await conversation.ready()
 for x in range(1,4):
        file_box = FileBox.from_url(
        'https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/'
        'u=1116676390,2305043183&fm=26&gp=0.jpg',
        name='ding-dong.jpg')
        time.sleep(5)
        await conversation.say(file_box)

and a scheduler job to run it (3 times per hour)

the picture didn't send into chat room when I hit this issue.

MrZilinXiao commented 4 years ago

I got the same issue...

                with open(ret_path, 'rb') as f:
                    content: str = base64.b64encode(f.read())
                    ret_img = FileBox.from_base64(name=os.path.basename(ret_path), base64=content)
                    await msg.say(ret_img)
why2lyj commented 4 years ago

@MrZilinXiao Hi bro, until now, here're some issue found but without solved by many times upgrade. I'd like to let you know the issue come from underlying framework.

the first one is this one: when we keep a long time to send the picture, we will get this issue. I've not idea to tell you how long bot will hit this issue, my bot send 10 pictures per hour and it will hit this issue in 8-10 hours.

the second is sending url_link, it will hit this issue as well.

After meeting this issue, we need to ask provider to restart our bot.

MrZilinXiao commented 4 years ago

@MrZilinXiao Hi bro, until now, here're some issue found but without solved by many times upgrade. I'd like to let you know the issue come from underlying framework.

the first one is this one: when we keep a long time to send the picture, we will get this issue. I've not idea to tell you how long bot will hit this issue, my bot send 10 pictures per hour and it will hit this issue in 8-10 hours.

the second is sending url_link, it will hit this issue as well.

After meeting this issue, we need to ask provider to restart our bot.

I have located the exception at https://github.com/wechaty/python-wechaty-puppet-hostie/blob/631841448dbaaa48dc1eb8718fc5c51c95f9a3fe/src/wechaty_puppet_hostie/puppet.py#L334, where image can be successfully received when response.id is returned, otherwise, it never returns, indicating await self.puppet_stub.message_send_file() may be the reason to raise this exception...

I didn't realize you have provided a detailed traceback... And one more thing, my exception seems to include more info related to file and to_wxid, <(<Status.INTERNAL: 13>, 'can not get message callback response, data: {"file":"C:\\\\users\\\\user\\\\Temp\\\\1601126521735-66c03461-8e25-4a21-822e-6a181f63fe2c.jpg","to_wxid":"REDACTED"}', None)>

MrZilinXiao commented 4 years ago
 Traceback (most recent call last):
   File "/usr/local/lib/python3.7/site-packages/apscheduler/executors/base_py3.py", line 29, in run_coroutine_job
     retval = await job.func(*job.args, **job.kwargs)
   File "/ding-dong-bot.py", line 199, in xxxx
     await conversation.say(file_box)
   File "/usr/local/lib/python3.7/site-packages/wechaty/user/room.py", line 266, in say
     file=some_thing
   File "/usr/local/lib/python3.7/site-packages/wechaty_puppet_hostie/puppet.py", line 322, in message_send_file
     filebox=file.to_json_str()
   File "/usr/local/lib/python3.7/site-packages/chatie_grpc/wechaty.py", line 886, in message_send_file
     "/wechaty.Puppet/MessageSendFile", request, MessageSendFileResponse,
   File "/usr/local/lib/python3.7/site-packages/betterproto/__init__.py", line 1124, in _unary_unary
     response = await stream.recv_message()
   File "/usr/local/lib/python3.7/site-packages/grpclib/client.py", line 387, in recv_message
     await self.recv_initial_metadata()
   File "/usr/local/lib/python3.7/site-packages/grpclib/client.py", line 355, in recv_initial_metadata
     self._raise_for_grpc_status(headers_map)
   File "/usr/local/lib/python3.7/site-packages/grpclib/client.py", line 316, in _raise_for_grpc_status
     raise GRPCError(status, message, details)
 grpclib.exceptions.GRPCError: (<Status.INTERNAL: 13>, 'can not get message callback response.', None)

I'm using scheduler to send pictures to a ChatRoom and got issue above code like followed:

 room = bot.Room.load("xxxxxxxxx@chatroom")
 conversation: Union[Room, Contact] = room
 await conversation.ready()
 for x in range(1,4):
        file_box = FileBox.from_url(
        'https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/'
        'u=1116676390,2305043183&fm=26&gp=0.jpg',
        name='ding-dong.jpg')
        time.sleep(5)
        await conversation.say(file_box)

and a scheduler job to run it (3 times per hour)

the picture didn't send into chat room when I hit this issue.

BTW, how to show full traceback when debugging, that could be very helpful...

why2lyj commented 4 years ago

@MrZilinXiao when we use Wechat PC, how do you send the picture? step 1. click send picture button step 2. choose a picture step 3. click send picture and the picture will send in wechat

but, how did wechaty do this? let's make an example: you're using picture's url step 1. this url picture must save on token server step 2. use puppet to send pictue (like above) step 3. delete this picture on token server during the save and delete picture it will be encrypted.

the step 3 with issue as far as I know, and this Friday, I meet the juzi core developer, he told me, it will fix after Oct. BTW, we can't find the detail information due to it on token server.

MrZilinXiao commented 4 years ago

@MrZilinXiao when we use Wechat PC, how do you send the picture? step 1. click send picture button step 2. choose a picture step 3. click send picture and the picture will send in wechat

but, how did wechaty do this? let's make an example: you're using picture's url step 1. this url picture must save on token server step 2. use puppet to send pictue (like above) step 3. delete this picture on token server during the save and delete picture it will be encrypted.

the step 3 with issue as far as I know, and this Friday, I meet the juzi core developer, he told me, it will fix after Oct. BTW, we can't find the detail information due to it on token server.

Thx for your illustrated interpretation! And hope this will be fixed ASAP.