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

The network is not good, the bot will try to restart after 60 seconds 的问题。谢谢 #304

Closed ashen001 closed 2 years ago

ashen001 commented 2 years ago

我使用0.68版出现了 Wechaty - ERROR - The network is not good, the bot will try to restart after 60 seconds.

在重新回到0.56版本后。脚本运行一段时间同样出现了 Wechaty - ERROR - The network is not good, the bot will try to restart after 60 seconds. 然后导致 scheduler 运行出错 Job "tick (trigger: interval[0:10:00], next run at: 2022-03-02 17:45:46 CST)" raised an exception Traceback (most recent call last):

请问我该如何解决。谢谢

=================================================================================== server的配置

!/bin/bash

export WECHATY_LOG="verbose" export WECHATY_PUPPET="wechaty-puppet-padlocal" export WECHATY_PUPPET_PADLOCAL_TOKEN="puppet_padlocal_xxxxxxxx"

export WECHATY_PUPPET_SERVER_PORT="9099" export WECHATY_TOKEN="888" export WECHATY_PUPPET_SERVICE_NO_TLS_INSECURE_SERVER="true"

docker run -ti --name wechaty_puppet_service_token_gateway --rm -e WECHATY_LOG -e WECHATY_PUPPET -e WECHATY_PUPPET_PADLOCAL_TOKEN -e WECHATY_PUPPET_SERVER_PORT -e WECHATY_TOKEN -p "$WECHATY_PUPPET_SERVER_PORT:$WECHATY_PUPPET_SERVER_PORT" wechaty/wechaty:0.68

=================================================================================== client端:

import os import asyncio from typing import Optional, Union

from wechaty import Wechaty, Contact, Room from wechaty.user import Message

from apscheduler.schedulers.asyncio import AsyncIOScheduler

from wechaty_puppet import get_logger

from datetime import datetime

logger = get_logger(name)

os.environ['WECHATY_PUPPET'] = "wechaty-puppet-service" os.environ['WECHATY_PUPPET_SERVICE_TOKEN'] = "888" os.environ['WECHATY_PUPPET_SERVICE_ENDPOINT'] = "101.xxx.xxx.xxx:9099" os.environ['WECHATY_PUPPET_SERVICE_NO_TLS_INSECURE_CLIENT'] = "true"

class MyBot(Wechaty): def init(self): super().init() self.busy = False self.auto_reply_comment = "Automatic Reply: I cannot read your message because I'm busy now, will talk to you when I get back."

async def on_message(self, msg: Message): """back on message""" from_contact = msg.talker()

text = msg.text()
room = msg.room()

if text == '#ding':
    conversation: Union[
        Room, Contact] = from_contact if room is None else room
    await conversation.ready()
    await conversation.say('dong')

async def on_login(self, contact: Contact): print(f'user: {contact} has login') bot: Optional[MyBot] = None

async def tick(bot: Wechaty): """ find a specific room, and say something to it. """ room = bot.Room.load('195625838710@chatroom') await room.ready() await room.say('#ding')

async def main(): """Async Main Entry""" if 'WECHATY_PUPPET_SERVICE_TOKEN' not in os.environ: print(''' Error: WECHATY_PUPPET_SERVICE_TOKEN is not found in the environment variables You need a TOKEN to run the Python Wechaty. Please goto our README for details https://github.com/wechaty/python-wechaty-getting-started/#wechaty_puppet_service_token ''')

global bot bot = MyBot()

scheduler = AsyncIOScheduler(timezone='Asia/Shanghai') scheduler.add_job(tick, 'interval', minutes=10, args=[bot])

scheduler.start() await bot.start() asyncio.run(main())

===================================================================================

非常感谢