MCPcopy Index your code
hub / github.com/wechaty/python-wechaty / start

Method start

src/wechaty/wechaty.py:423–475  ·  view source on GitHub ↗

start wechaty bot Args: None Examples: >>> from wechaty import Wechaty >>> bot = Wechaty() >>> await bot.start() Returns: None

(self)

Source from the content-addressed store, hash-verified

421 """
422
423 async def start(self) -> None:
424 """
425 start wechaty bot
426 Args:
427 None
428 Examples:
429 >>> from wechaty import Wechaty
430 >>> bot = Wechaty()
431 >>> await bot.start()
432 Returns:
433 None
434 """
435
436 # If the network is shut-down, we should catch the connection
437 # error and restart after a minute.
438 try:
439
440 await self.init_puppet()
441 await self.init_puppet_event_bridge(self.puppet)
442
443 log.info('starting puppet ...')
444 await self.puppet.start()
445
446 self.started = True
447
448 # register the system signal
449
450 except (requests.exceptions.ConnectionError, StreamTerminatedError, OSError):
451
452 # TODO: this problem is the most common error, so I add chinese & detail info for
453 # developer. this should be removed later.
454 # pylint: disable=C0301
455 error_info = '''The network is not good, the bot will try to restart after 60 seconds.
456But here are some suggestions for you:
457* 查看token是否可用?(过期或协议不可用)
458* docker 服务是否正常启动?
459* python-wechaty bot 是否正常启动?
460* python-wechaty bot 是否能ping通docker服务?
461* 由于版本细节问题,目前python-wechaty 支持最好的wechaty镜像为:[wechaty/wechaty:0.65](https://hub.docker.com/layers/wechaty/wechaty/0.65/images/sha256-d39b9fb5dece3a8ffa88b80a8ccfd916be14b9d0de72115732c3ee714b0d6a96?context=explore)
462
463I suggest that you should follow the template code from: https://wechaty.readthedocs.io/zh_CN/latest/ to avoid the unnecessary bugs.
464'''
465 log.error(error_info)
466 await asyncio.sleep(60)
467 await self.restart()
468
469 except WechatyPuppetError:
470 traceback.print_exc()
471 loop = asyncio.get_event_loop()
472 loop.stop()
473
474 except Exception as e: # pylint: disable=broad-except
475 print(e)
476
477 async def restart(self) -> None:
478 """

Callers 6

restartMethod · 0.95
login_listenerMethod · 0.45
mainFunction · 0.45
mainFunction · 0.45
mainFunction · 0.45
mainFunction · 0.45

Calls 4

init_puppetMethod · 0.95
restartMethod · 0.95
stopMethod · 0.45

Tested by

no test coverage detected