{"id":28461,"library":"wecom-aibot-python-sdk","title":"WeCom AI Bot Python SDK","description":"企业微信智能机器人 Python SDK，基于 WebSocket 长连接通道，提供消息收发、流式回复、模板卡片、事件回调、文件下载解密等核心能力。当前版本 1.0.2，要求 Python >=3.8。","status":"active","version":"1.0.2","language":"python","source_language":"en","source_url":"https://github.com/WecomTeam/wecom-aibot-python-sdk","tags":["wecom","wechat-work","bot","websocket","sdk"],"install":[{"cmd":"pip install wecom-aibot-python-sdk","lang":"bash","label":"Install from PyPI"}],"dependencies":[{"reason":"WebSocket 长连接依赖","package":"websockets","optional":false},{"reason":"消息加解密和文件解密","package":"cryptography","optional":false}],"imports":[{"note":"包名使用下划线，非连字符","wrong":"from wecom_aibot_python_sdk import WeComBot","symbol":"WeComBot","correct":"from wecom_aibot import WeComBot"},{"note":"文本消息类","symbol":"TextMsg","correct":"from wecom_aibot import TextMsg"},{"note":"Markdown 消息类","symbol":"MarkdownMsg","correct":"from wecom_aibot import MarkdownMsg"}],"quickstart":{"code":"import os\nfrom wecom_aibot import WeComBot\n\nbot = WeComBot(\n    app_id=os.environ.get('WECOM_APP_ID', ''),\n    app_secret=os.environ.get('WECOM_APP_SECRET', ''),\n    token=os.environ.get('WECOM_TOKEN', ''),\n    encoding_aes_key=os.environ.get('WECOM_ENCODING_AES_KEY', '')\n)\n\n@bot.on_message()\ndef echo(msg):\n    return msg.reply_text('Hello from WeCom Bot!')\n\nbot.run()","lang":"python","description":"初始化机器人并注册消息监听，运行 WebSocket 连接。"},"warnings":[{"fix":"升级后使用 @bot.on_message() 替代 @bot.on_text ","message":"v1.0.0 至 v1.0.2 之间回调注册方式变更，旧版使用 @bot.on_text 现已改为 @bot.on_message()。","severity":"breaking","affected_versions":"<1.0.0"},{"fix":"请确保在企微后台的『机器人』配置中复制正确的 Token 和 EncodingAESKey。","message":"token 和 encoding_aes_key 需从企业微信后台获取，如果填错会导致连接失败且无明确错误提示。","severity":"gotcha","affected_versions":"all"},{"fix":"改为 from wecom_aibot import ...","message":"旧版导入路径 from wecom_aibot_python_sdk import ... 在 v1.0.0 后不再支持。","severity":"deprecated","affected_versions":"<1.0.0"}],"env_vars":null,"last_verified":"2026-05-09T00:00:00.000Z","next_check":"2026-08-07T00:00:00.000Z","problems":[{"fix":"使用 from wecom_aibot import WeComBot","cause":"包名不是连字符，应为下划线 wecom_aibot。","error":"ModuleNotFoundError: No module named 'wecom_aibot_python_sdk'"},{"fix":"检查 app_id 是否正确，确认企微后台已开启机器人并配置了 IP 白名单。","cause":"WebSocket 连接地址错误或网络不通，或企微后台未启用机器人。","error":"ConnectionRefusedError: ..."},{"fix":"确保传入 app_id, app_secret, token, encoding_aes_key 四个参数。","cause":"实例化 WeComBot 未传入必要参数。","error":"TypeError: __init__() missing 4 required positional arguments: 'app_id', 'app_secret', 'token', 'encoding_aes_key'"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}