python-wechaty
python-wechaty copied to clipboard
⁉ assert response is not None ⁉
requirements
- token type(one of web protocol) [required]
- version of python-wechaty 0.8.25[required]
- version of wechaty docker image latest[optional]
Describe your problem
按照这个教程做的:https://wechaty.js.org/2021/04/17/python-wechaty-use-web/
按照上面那个教程,在远程服务器上面使用Docker启动web协议服务,docker应该是正常启动了,后面打印了QRcode的网址之类的。
Reproduce your problem
在运行示例代码的时候报错,assert response is not None
Error info
assert response is not None
Your experiments
我使用的是虚拟机中的docker启动的容器,有可能是容器需要使用虚拟机的网络(这个是群里的大佬指导的)
我在启动容器的时候增加了--network host 就可以成功运行了 但是这个问题我现在无法复现了,因为我现在即使不加--network host 也可以正常的成功运行
下边是我的docker启动代码
export WECHATY_LOG="verbose"
export WECHATY_PUPPET="wechaty-puppet-wechat"
export WECHATY_PUPPET_SERVER_PORT="8877" 端口可以自定义
export WECHATY_TOKEN="python-wechaty-5c49627d-d360-4a1a-a2be-bbed8d37aeff" 这个token是我自定义的
export WECHATY_PUPPET_SERVICE_NO_TLS_INSECURE_SERVER="true"
docker run -ti --name wechaty_puppet_service_local --rm --network host -e WECHATY_LOG -e WECHATY_PUPPET -e WECHATY_PUPPET_SERVER_PORT -e WECHATY_TOKEN -e WECHATY_PUPPET_SERVICE_NO_TLS_INSECURE_SERVER -p "$WECHATY_PUPPET_SERVER_PORT:$WECHATY_PUPPET_SERVER_PORT" wechaty/wechaty:latest
我的示例代码
from wechaty import Wechaty
import os
os.environ['WECHATY_PUPPET_SERVICE_TOKEN'] = "python-wechaty-5c49627d-d360-4a1a-a2be-bbed8d37aeff"
os.environ['WECHATY_PUPPET_SERVICE_ENDPOINT'] = "192.168.157.128:8877"
os.environ['WECHATY_PUPPET_SERVICE_NO_TLS_INSECURE_CLIENT'] = 'true'
import asyncio
async def main():
bot = Wechaty()
bot.on('scan', lambda status, qrcode, data: print('Scan QR Code to login: {}\nhttps://wechaty.js.org/qrcode/{}'.format(status, qrcode)))
bot.on('login', lambda user: print('User {} logged in'.format(user)))
bot.on('message', lambda message: print('Message: {}'.format(message)))
await bot.start()
asyncio.run(main())
Your solution is great, you can refer to web protocol to get more details about starting docker service. Thanks for your sharing.