wechaty / python-wechaty-getting-started

Python Wechaty Starter Project Template that Works Out-of-the-Box
https://gitpod.io/#https://github.com/wechaty/python-wechaty-getting-started
Apache License 2.0
185 stars 55 forks source link

连接失败 #82

Open linghaohuang opened 2 years ago

linghaohuang commented 2 years ago

运行 ding-dong-bot.py 后,我得到以下消息:

2022-07-14 09:38:15,183 - Wechaty - INFO - on() listen event with <<function on_scan at 0x10bb9d3f0>> 2022-07-14 09:38:15,183 - Wechaty - INFO - on() listen event with <<function on_login at 0x10d3b41f0>> 2022-07-14 09:38:15,183 - Wechaty - INFO - on() listen event with <<function on_message at 0x10a8a4700>> 2022-07-14 09:38:15,195 - Wechaty - INFO - init_puppet_event_bridge() <<wechaty_puppet_service.puppet.PuppetService object at 0x10d61ded0>> 2022-07-14 09:38:15,195 - Wechaty - INFO - initPuppetEventBridge() puppet.on(dong) (listenerCount:1) registering... 2022-07-14 09:38:15,195 - Wechaty - INFO - initPuppetEventBridge() puppet.on(error) (listenerCount:1) registering... 2022-07-14 09:38:15,195 - Wechaty - INFO - initPuppetEventBridge() puppet.on(heart-beat) (listenerCount:1) registering... 2022-07-14 09:38:15,195 - Wechaty - INFO - initPuppetEventBridge() puppet.on(ready) (listenerCount:1) registering... 2022-07-14 09:38:15,195 - Wechaty - INFO - receive event <%s> 2022-07-14 09:38:15,195 - Wechaty - INFO - initPuppetEventBridge() puppet.on(reset) (listenerCount:0) registering... 2022-07-14 09:38:15,195 - Wechaty - INFO - initPuppetEventBridge() puppet.on(friendship) (listenerCount:1) registering... 2022-07-14 09:38:15,195 - Wechaty - INFO - initPuppetEventBridge() puppet.on(login) (listenerCount:1) registering... 2022-07-14 09:38:15,195 - Wechaty - INFO - initPuppetEventBridge() puppet.on(logout) (listenerCount:1) registering... 2022-07-14 09:38:15,195 - Wechaty - INFO - initPuppetEventBridge() puppet.on(message) (listenerCount:1) registering... 2022-07-14 09:38:15,195 - Wechaty - INFO - initPuppetEventBridge() puppet.on(room-invite) (listenerCount:1) registering... 2022-07-14 09:38:15,195 - Wechaty - INFO - initPuppetEventBridge() puppet.on(room-join) (listenerCount:1) registering... 2022-07-14 09:38:15,195 - Wechaty - INFO - initPuppetEventBridge() puppet.on(room-leave) (listenerCount:1) registering... 2022-07-14 09:38:15,195 - Wechaty - INFO - initPuppetEventBridge() puppet.on(room-topic) (listenerCount:1) registering... 2022-07-14 09:38:15,195 - Wechaty - INFO - initPuppetEventBridge() puppet.on(scan) (listenerCount:1) registering... 2022-07-14 09:38:15,195 - Wechaty - INFO - starting puppet ... 2022-07-14 09:38:15,195 - PuppetService - INFO - init puppet ... 2022-07-14 09:38:15,195 - PuppetService - INFO - fetching endpoint from chatie-server: https://api.chatie.io/v0/hosties/puppet_padlocal_187a9a65139c4bf482654606645f9da1 2022-07-14 09:38:16,818 - PuppetService - INFO - starting the puppet ... 2022-07-14 09:38:16,957 - Wechaty - ERROR - The network is not good, the bot will try to restart after 60 seconds. But here are some suggestions for you:

I suggest that you should follow the template code from: https://wechaty.readthedocs.io/zh_CN/latest/ to avoid the unnecessary bugs.

2022-07-14 09:39:16,951 - Wechaty - INFO - restarting the bot ... 2022-07-14 09:39:16,952 - Wechaty - INFO - wechaty is stopping ... 2022-07-14 09:39:16,952 - PuppetService - INFO - stop() Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/grpclib/client.py", line 368, in recv_initial_metadata headers = await self._stream.recv_headers() File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/grpclib/protocol.py", line 342, in recv_headers await self.headers_received.wait() File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/asyncio/locks.py", line 214, in wait await fut asyncio.exceptions.CancelledError

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/wechaty_puppet_service/puppet.py", line 916, in start await self.puppet_stub.stop() File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/wechaty_grpc/wechaty/init.py", line 25, in stop return await self._unary_unary( File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/betterproto/init.py", line 1124, in _unary_unary response = await stream.recv_message() File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/grpclib/client.py", line 425, in recv_message await self.recv_initial_metadata() File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/grpclib/client.py", line 367, in recv_initial_metadata with self._wrapper: File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/grpclib/utils.py", line 70, in exit raise self._error grpclib.exceptions.StreamTerminatedError: Connection lost

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/wechaty/wechaty.py", line 396, in start await self.puppet.start() File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/wechaty_puppet_service/puppet.py", line 918, in start await self.puppet_stub.start() File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/betterproto/init.py", line 1124, in _unary_unary response = await stream.recv_message() File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/grpclib/client.py", line 425, in recv_message await self.recv_initial_metadata() File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/grpclib/client.py", line 367, in recv_initial_metadata with self._wrapper: File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/grpclib/utils.py", line 70, in exit raise self._error grpclib.exceptions.StreamTerminatedError: Connection lost

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/Users/huanglinghao/Desktop/test_python/python-wechaty-getting-started/examples/ding-dong-bot.py", line 100, in asyncio.run(main()) File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/asyncio/runners.py", line 44, in run return loop.run_until_complete(main) File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/asyncio/base_events.py", line 646, in run_until_complete return future.result() File "/Users/huanglinghao/Desktop/test_python/python-wechaty-getting-started/examples/ding-dong-bot.py", line 95, in main await bot.start() File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/wechaty/wechaty.py", line 417, in start await self.restart() File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/betterproto/init.py", line 1124, in _unary_unary response = await stream.recv_message() File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/grpclib/client.py", line 425, in recv_message await self.recv_initial_metadata() File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/grpclib/client.py", line 367, in recv_initial_metadata with self._wrapper: File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/grpclib/utils.py", line 70, in exit raise self._error grpclib.exceptions.StreamTerminatedError: Connection lost

wj-Mcat commented 2 years ago

Which protocol do you use ? Web or Padlocal ?

we create a bot template project for developer, you can refer to this repo and try to start your bot. Hope you can start your bot when following this readme.

sevenler commented 1 year ago

i got the same issue:

2023-06-26 15:16:10,691 - Wechaty - INFO - initPuppetEventBridge() puppet.on(room-leave) (listenerCount:1) registering...
2023-06-26 15:16:10,691 - Wechaty - INFO - initPuppetEventBridge() puppet.on(room-topic) (listenerCount:1) registering...
2023-06-26 15:16:10,691 - Wechaty - INFO - initPuppetEventBridge() puppet.on(scan) (listenerCount:1) registering...
2023-06-26 15:16:10,691 - Wechaty - INFO - starting puppet ...
2023-06-26 15:16:10,691 - PuppetService - INFO - init puppet ...
2023-06-26 15:16:10,691 - PuppetService - INFO - fetching endpoint from chatie-server: https://api.chatie.io/v0/hosties/puppet_padlocal_3063184fc8a94a288547386b649ad5ae
2023-06-26 15:16:12,268 - PuppetService - INFO - starting the puppet ...
2023-06-26 15:16:12,760 - Wechaty - ERROR - The network is not good, the bot will try to restart after 60 seconds.
But here are some suggestions for you:

查看token是否可用?(过期或协议不可用)
docker 服务是否正常启动?
python-wechaty bot 是否正常启动?
python-wechaty bot 是否能ping通docker服务?
由于版本细节问题,目前python-wechaty 支持最好的wechaty镜像为:[wechaty/wechaty:0.65](https://hub.docker.com/layers/wechaty/wechaty/0.65/images/sha256-d39b9fb5dece3a8ffa88b80a8ccfd916be14b9d0de72115732c3ee714b0d6a96?context=explore)
I suggest that you should follow the template code from: https://wechaty.readthedocs.io/zh_CN/latest/ to avoid the unnecessary bugs.

2023-06-26 15:17:12,763 - Wechaty - INFO - restarting the bot ...
2023-06-26 15:17:12,764 - Wechaty - INFO - wechaty is stopping ...
2023-06-26 15:17:12,764 - PuppetService - INFO - stop()
Traceback (most recent call last):
File "/Users/daniel/.pyenv/versions/3.7.15/lib/python3.7/site-packages/grpclib/client.py", line 368, in recv_initial_metadata
headers = await self._stream.recv_headers()
File "/Users/daniel/.pyenv/versions/3.7.15/lib/python3.7/site-packages/grpclib/protocol.py", line 342, in recv_headers
await self.headers_received.wait()
File "/Users/daniel/.pyenv/versions/3.7.15/lib/python3.7/asyncio/locks.py", line 293, in wait
await fut
concurrent.futures._base.CancelledError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "examples/ding-dong-bot.py", line 100, in
asyncio.run(main())
File "/Users/daniel/.pyenv/versions/3.7.15/lib/python3.7/asyncio/runners.py", line 43, in run
return loop.run_until_complete(main)
File "/Users/daniel/.pyenv/versions/3.7.15/lib/python3.7/asyncio/base_events.py", line 587, in run_until_complete
return future.result()
File "examples/ding-dong-bot.py", line 95, in main
await bot.start()
File "/Users/daniel/.pyenv/versions/3.7.15/lib/python3.7/site-packages/wechaty/wechaty.py", line 468, in start
await self.restart()
File "/Users/daniel/.pyenv/versions/3.7.15/lib/python3.7/site-packages/wechaty/wechaty.py", line 491, in restart
await self.stop()
File "/Users/daniel/.pyenv/versions/3.7.15/lib/python3.7/site-packages/wechaty/wechaty.py", line 812, in stop
await self.puppet.stop()
File "/Users/daniel/.pyenv/versions/3.7.15/lib/python3.7/site-packages/wechaty_puppet_service/puppet.py", line 931, in stop
await self._puppet_stub.stop()
File "/Users/daniel/.pyenv/versions/3.7.15/lib/python3.7/site-packages/wechaty_grpc/wechaty/init.py", line 26, in stop
"/wechaty.Puppet/Stop", request, puppet.StopResponse
File "/Users/daniel/.pyenv/versions/3.7.15/lib/python3.7/site-packages/betterproto/init.py", line 1124, in _unary_unary
response = await stream.recv_message()
File "/Users/daniel/.pyenv/versions/3.7.15/lib/python3.7/site-packages/grpclib/client.py", line 425, in recv_message
await self.recv_initial_metadata()
File "/Users/daniel/.pyenv/versions/3.7.15/lib/python3.7/site-packages/grpclib/client.py", line 397, in recv_initial_metadata
self.initial_metadata = im
File "/Users/daniel/.pyenv/versions/3.7.15/lib/python3.7/site-packages/grpclib/utils.py", line 70, in exit
raise self._error
grpclib.exceptions.StreamTerminatedError: Connection lost
make: *** [bot] Error 1

this is log from wechaty-puppet-padlocal server

 07:16:11 INFO Io on(jsonrpc): [object Object] 07:16:11 VERB Io on(jsonrpc) send({"id":-9007199254740856,"jsonrpc":"2.0","result":8788}) 07:17:13 VERB Message find({"id":"4564539897230661817"}) 

it looks like python puppet client is already connected to the padlocal server. but got StreamTerminatedError error. i am following the guide: https://wechaty.js.org/docs/puppet-services/padlocal

any way to fix this ?

wenmj commented 6 months ago

how to deal with this error