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

in docker model with latest tag, can't initiate the python demo bot because of the network error #286

Closed Allencccc closed 3 weeks ago

Allencccc commented 2 years ago

🚨 The issue tracker is not for questions 🚨

If you have a question, please ask it on https://stackoverflow.com/questions/tagged/wechaty

[question] I can launch docker image with latest tag and curl the right data from https://api.chatie.io/v0/hosties. BUT after run the ding-dong-bot.py, the exception says: The network seems not good.

os & docker

docker: Docker version 20.10.11, build dea9396
python: 3.9.9
centos 8: centos 4.18.0-348.el8.x86_64
wechaty: latest from docker

wechaty

wechaty: docker image with latest tag
token: 7days-free token

export WECHATY_PUPPET="wechaty-puppet-padlocal"
export WECHATY_PUPPET_PADLOCAL_TOKEN="puppet_padlocal_xxxxxx"

python lib

wechaty                           0.8.25
wechaty-grpc                      0.20.19
wechaty-puppet                    0.3.dev10
wechaty-puppet-service            0.8.5

BUT When I change tag to 0.56, everything goes well. Nothing changed except docker image tag.

Whether some bugs in that image? or python lib?

huan commented 2 years ago

In order to make your situation to be clear, you need to provide a minimum code with reproducible steps.

Allencccc commented 2 years ago
  1. docker images:
REPOSITORY        TAG       IMAGE ID       CREATED         SIZE
wechaty/wechaty   latest    40196fb204e1   2 weeks ago     2.49GB
wechaty/wechaty   0.56      2ce7bd6395ba   10 months ago   2.27GB
  1. I made a configure file for source
echo "== initial WECHATY env =="
export WECHATY_LOG="verbose"
export WECHATY_PUPPET="wechaty-puppet-padlocal"
export WECHATY_PUPPET_PADLOCAL_TOKEN="my_puppet_padlocal_token"

export WECHATY_PUPPET_SERVER_PORT="9099"
export WECHATY_TOKEN="my_uuid"

#import version
export VERSION="0.56"
  1. docker run shell
sudo docker run -ti \
  --name wechaty_token_gateway \
  --rm \
  -e WECHATY_LOG="$WECHATY_LOG" \
  -e WECHATY_PUPPET="$WECHATY_PUPPET" \
  -e WECHATY_PUPPET_PADLOCAL_TOKEN="$WECHATY_PUPPET_PADLOCAL_TOKEN" \
  -e WECHATY_PUPPET_SERVER_PORT="$WECHATY_PUPPET_SERVER_PORT" \
  -e WECHATY_TOKEN="$WECHATY_TOKEN" \
  -p "$WECHATY_PUPPET_SERVER_PORT:$WECHATY_PUPPET_SERVER_PORT" \
  wechaty/wechaty:$VERSION
  1. ding-dong-bot.py from git
from wechaty import (
    Contact,
    FileBox,
    Message,
    Wechaty,
    ScanStatus,
)

os.environ['WECHATY_PUPPET']="wechaty-puppet-service"
os.environ['WECHATY_PUPPET_SERVICE_TOKEN']="my_uuid"
os.environ['WECHATY_PUPPET_SERVICE_ENDPOINT']="192.168.10.163:9099"

async def on_message(msg: Message):
  1. runtime:

5.1 VERSION = 0.56, everything goes well.

5.2 VERSION = latest:

02:09:49 VERB PuppetServer start() initializing authorization with token ... done
02:09:49 VERB PuppetServer start() initializing gRPC health service ...
02:09:49 VERB PuppetServer start() initializing gRPC health service ... done
02:09:49 VERB PuppetServer start() initializing TLS CA ...
02:09:49 VERB PuppetServer start() initializing TLS CA ... done
02:09:49 VERB PuppetServer start() initializing gRPC server credentials ...
02:09:49 VERB PuppetServer start() TLS enabled.
02:09:49 VERB PuppetServer start() initializing gRPC server credentials ... done
02:09:49 VERB PuppetServer start() gRPC server starting ...
02:09:49 VERB PuppetServer start() gRPC server starting ... done
02:09:49 VERB StateSwitch <IoClient> active(true) <- (pending)

Gateway console shows:

02:11:45 INFO Io on(jsonrpc): [object Object]
02:11:45 VERB Io on(jsonrpc) send({"id":-9007199254700085,"jsonrpc":"2.0","result":9099})
2021-12-12 10:16:20,089 - Wechaty - INFO - on() listen event <scan> with <<function on_scan at 0x7fc23f7a70d0>>
2021-12-12 10:16:20,090 - Wechaty - INFO - on() listen event <login> with <<function on_login at 0x7fc23a56c280>>
2021-12-12 10:16:20,090 - Wechaty - INFO - on() listen event <message> with <<function on_message at 0x7fc241ab3040>>
2021-12-12 10:16:20,125 - Wechaty - INFO - init_puppet_event_bridge() <<wechaty_puppet_service.puppet.PuppetService object at 0x7fc23a569220>>
2021-12-12 10:16:20,125 - Wechaty - INFO - initPuppetEventBridge() puppet.on(dong) (listenerCount:1) registering...
2021-12-12 10:16:20,125 - Wechaty - INFO - initPuppetEventBridge() puppet.on(error) (listenerCount:1) registering...
2021-12-12 10:16:20,126 - Wechaty - INFO - initPuppetEventBridge() puppet.on(heart-beat) (listenerCount:1) registering...
2021-12-12 10:16:20,126 - Wechaty - INFO - initPuppetEventBridge() puppet.on(ready) (listenerCount:1) registering...
2021-12-12 10:16:20,126 - Wechaty - INFO - receive <reset> event <%s>
2021-12-12 10:16:20,126 - Wechaty - INFO - initPuppetEventBridge() puppet.on(reset) (listenerCount:0) registering...
2021-12-12 10:16:20,126 - Wechaty - INFO - initPuppetEventBridge() puppet.on(friendship) (listenerCount:1) registering...
2021-12-12 10:16:20,126 - Wechaty - INFO - initPuppetEventBridge() puppet.on(login) (listenerCount:1) registering...
2021-12-12 10:16:20,126 - Wechaty - INFO - initPuppetEventBridge() puppet.on(logout) (listenerCount:1) registering...
2021-12-12 10:16:20,126 - Wechaty - INFO - initPuppetEventBridge() puppet.on(message) (listenerCount:1) registering...
2021-12-12 10:16:20,127 - Wechaty - INFO - initPuppetEventBridge() puppet.on(room-invite) (listenerCount:1) registering...
2021-12-12 10:16:20,127 - Wechaty - INFO - initPuppetEventBridge() puppet.on(room-join) (listenerCount:1) registering...
2021-12-12 10:16:20,127 - Wechaty - INFO - initPuppetEventBridge() puppet.on(room-leave) (listenerCount:1) registering...
2021-12-12 10:16:20,127 - Wechaty - INFO - initPuppetEventBridge() puppet.on(room-topic) (listenerCount:1) registering...
2021-12-12 10:16:20,127 - Wechaty - INFO - initPuppetEventBridge() puppet.on(scan) (listenerCount:1) registering...
2021-12-12 10:16:20,127 - Wechaty - INFO - starting puppet ...
2021-12-12 10:16:20,127 - HostiePuppet - INFO - init puppet
2021-12-12 10:16:20,130 - HostiePuppet - INFO - starting the puppet ...
2021-12-12 10:16:20,135 - Wechaty - ERROR - The network is not good, the bot will try to restart after 60 seconds.

after 60s

2021-12-12 10:17:20,195 - Wechaty - INFO - restarting the bot ...
2021-12-12 10:17:20,195 - Wechaty - INFO - wechaty is stoping ...
2021-12-12 10:17:20,195 - Wechaty - INFO - stopping - stop puppet
2021-12-12 10:17:20,196 - HostiePuppet - INFO - stop()
Traceback (most recent call last):
  File "/home/allen/.local/lib/python3.9/site-packages/grpclib/client.py", line 368, in recv_initial_metadata
    headers = await self._stream.recv_headers()
  File "/home/allen/.local/lib/python3.9/site-packages/grpclib/protocol.py", line 342, in recv_headers
    await self.headers_received.wait()
  File "/usr/local/python3/lib/python3.9/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 "/home/allen/.local/lib/python3.9/site-packages/wechaty_puppet_service/puppet.py", line 926, in start
    await self.puppet_stub.stop()
  File "/home/allen/.local/lib/python3.9/site-packages/wechaty_grpc/wechaty/__init__.py", line 25, in stop
    return await self._unary_unary(
  File "/home/allen/.local/lib/python3.9/site-packages/betterproto/__init__.py", line 1124, in _unary_unary
    response = await stream.recv_message()
  File "/home/allen/.local/lib/python3.9/site-packages/grpclib/client.py", line 425, in recv_message
    await self.recv_initial_metadata()
  File "/home/allen/.local/lib/python3.9/site-packages/grpclib/client.py", line 397, in recv_initial_metadata
    self.initial_metadata = im
  File "/home/allen/.local/lib/python3.9/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 "/home/allen/.local/lib/python3.9/site-packages/wechaty/wechaty.py", line 424, in start
    await self.puppet.start()
  File "/home/allen/.local/lib/python3.9/site-packages/wechaty_puppet_service/puppet.py", line 928, in start
    await self.puppet_stub.start()
  File "/home/allen/.local/lib/python3.9/site-packages/betterproto/__init__.py", line 1124, in _unary_unary
    response = await stream.recv_message()
  File "/home/allen/.local/lib/python3.9/site-packages/grpclib/client.py", line 425, in recv_message
    await self.recv_initial_metadata()
  File "/home/allen/.local/lib/python3.9/site-packages/grpclib/client.py", line 397, in recv_initial_metadata
    self.initial_metadata = im
  File "/home/allen/.local/lib/python3.9/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 "/home/allen/docker/wechaty/ding-dong-bot.py", line 97, in <module>
    asyncio.run(main())
  File "/usr/local/python3/lib/python3.9/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/usr/local/python3/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete
    return future.result()
  File "/home/allen/docker/wechaty/ding-dong-bot.py", line 92, in main
    await bot.start()
  File "/home/allen/.local/lib/python3.9/site-packages/wechaty/wechaty.py", line 434, in start
    await self.restart()
  File "/home/allen/.local/lib/python3.9/site-packages/wechaty/wechaty.py", line 766, in stop
    await self.puppet.stop()
  File "/home/allen/.local/lib/python3.9/site-packages/wechaty_puppet_service/puppet.py", line 941, in stop
    await self._puppet_stub.stop()
  File "/home/allen/.local/lib/python3.9/site-packages/wechaty_grpc/wechaty/__init__.py", line 25, in stop
    return await self._unary_unary(
  File "/home/allen/.local/lib/python3.9/site-packages/betterproto/__init__.py", line 1124, in _unary_unary
    response = await stream.recv_message()
  File "/home/allen/.local/lib/python3.9/site-packages/grpclib/client.py", line 425, in recv_message
    await self.recv_initial_metadata()
  File "/home/allen/.local/lib/python3.9/site-packages/grpclib/client.py", line 397, in recv_initial_metadata
    self.initial_metadata = im
  File "/home/allen/.local/lib/python3.9/site-packages/grpclib/utils.py", line 70, in __exit__
    raise self._error
grpclib.exceptions.StreamTerminatedError: Connection lost

Gateway console did not change.

ZLL94 commented 2 years ago

可能是TLS,你可以看一下#272

wj-Mcat commented 2 years ago

You can disable TLS with environment variable: WECHATY_PUPPET_SERVICE_NO_TLS_INSECURE_SERVER. You can find example code in: https://wechaty.readthedocs.io/zh_CN/latest/introduction/use-web-protocol/