👋 corpwechatbot
是一个python
封装的企业机器人&应用消息推送库,通过企业微信提供的api实现。
利用本库,你可以轻松地实现从服务器端发送一条文本、图片、视频、markdown
等等消息到你的微信手机端,而不依赖于其他的第三方应用
本项目遵守GPL v3开源协议
本项目完全出于公益性质开源使用,作者独自完成开发测试等一系列工作,如果它帮到了你,解决了你的痛点需求,你可以请作者喝杯阔乐,或者给这个项目一个star
(右上角),激励作者继续更新完善本项目,非常感谢🙏
企业微信的python封装接口,简易上手,开箱即用,一行代码实现消息推送。A more convenient python wrapper interface of corpwechat(wework, wecom) official API, use only one line of code to send your messages to your corpwechat(wework, wecom) .
Home Page: https://corpwechatbot.gentlecp.com
License: GNU General Public License v3.0
👋 corpwechatbot
是一个python
封装的企业机器人&应用消息推送库,通过企业微信提供的api实现。
利用本库,你可以轻松地实现从服务器端发送一条文本、图片、视频、markdown
等等消息到你的微信手机端,而不依赖于其他的第三方应用
本项目遵守GPL v3开源协议
本项目完全出于公益性质开源使用,作者独自完成开发测试等一系列工作,如果它帮到了你,解决了你的痛点需求,你可以请作者喝杯阔乐,或者给这个项目一个star
(右上角),激励作者继续更新完善本项目,非常感谢🙏
self.corp_wechat_app.send_markdown(m)
File "/usr/local/lib/python3.10/site-packages/corpwechatbot/app.py", line 379, in send_markdown
if md_path.is_file():
File "/usr/local/lib/python3.10/pathlib.py", line 1322, in is_file
return S_ISREG(self.stat().st_mode)
File "/usr/local/lib/python3.10/pathlib.py", line 1097, in stat
return self._accessor.stat(self, follow_symlinks=follow_symlinks)
OSError: [Errno 36] Filename too long: '
看了一下代码,把发送的内容构建一个Path判断是否是文件,导致os抛出文件名过长,作者这里是否可以加个内容长度判断
能发消息到我的私人微信客户端吗?
根据api请求的access_token和在管理后台接收消息里配置的token是不是同一个啊?不是同一个它们有什么关系?
请问可以出一个和腾讯云开发的定时器联动的教程吗? 萌新想搞一个定时回复,不会配置0.0
大佬能支持下mpnews这种类型的图文发送吗 拜托感谢
位于
https://github.com/GentleCP/corpwechat-bot/blob/29d396dc13b82243a3960b33a83ba4c4aea87d23/corpwechatbot/app.py
的源码
CUR_PATH = Path(__file__)
TOKEN_PATH = CUR_PATH.parent.joinpath('token.txt') # 存储在本项目根目录下
缓存了token,但是根据企业微信的api的报错来看,not allow operate another agent with this accesstoken,针对不同的自建第三方应用,需要不同的token,这里缓存的token应该对此作出调整。
复现步骤,创建两个不同的自建应用。
分别使用不同的应用的corpsecret和agentid创建AppMsgSender实例,用不同的AppMsgSender推送消息到客户端。
源代码取自:https://gist.github.com/GentleCP
源代码未做任何修改,但是Crypto.Cipher模块pycrypto已经无法安装了,百度后使用的替代品pycryptodome(安装方式 pip install pycryptodome)
部署到腾讯云上后可以正常运行,但是每次收发消息都会报错:
ERROR: Exception in ASGI application
Traceback (most recent call last):
File "/usr/local/python3/lib/python3.8/site-packages/uvicorn/protocols/http/h11_impl.py", line 373, in run_asgi
result = await app(self.scope, self.receive, self.send)
File "/usr/local/python3/lib/python3.8/site-packages/uvicorn/middleware/proxy_headers.py", line 75, in call
return await self.app(scope, receive, send)
File "/usr/local/python3/lib/python3.8/site-packages/fastapi/applications.py", line 208, in call
await super().call(scope, receive, send)
File "/usr/local/python3/lib/python3.8/site-packages/starlette/applications.py", line 112, in call
await self.middleware_stack(scope, receive, send)
File "/usr/local/python3/lib/python3.8/site-packages/starlette/middleware/errors.py", line 181, in call
raise exc from None
File "/usr/local/python3/lib/python3.8/site-packages/starlette/middleware/errors.py", line 159, in call
await self.app(scope, receive, _send)
File "/usr/local/python3/lib/python3.8/site-packages/starlette/exceptions.py", line 82, in call
raise exc from None
File "/usr/local/python3/lib/python3.8/site-packages/starlette/exceptions.py", line 71, in call
await self.app(scope, receive, sender)
File "/usr/local/python3/lib/python3.8/site-packages/starlette/routing.py", line 580, in call
await route.handle(scope, receive, send)
File "/usr/local/python3/lib/python3.8/site-packages/starlette/routing.py", line 241, in handle
await self.app(scope, receive, send)
File "/usr/local/python3/lib/python3.8/site-packages/starlette/routing.py", line 52, in app
response = await func(request)
File "/usr/local/python3/lib/python3.8/site-packages/fastapi/routing.py", line 226, in app
raw_response = await run_endpoint_function(
File "/usr/local/python3/lib/python3.8/site-packages/fastapi/routing.py", line 159, in run_endpoint_function
return await dependant.call(**values)
File "/home/zk/mycode/wx_web/web.py", line 112, in recv
ret, send_msg = wxcpt.EncryptMsg(sReplyMsg=sRespData, sNonce=nonce)
UnboundLocalError: local variable 'sRespData' referenced before assignment
首先非常感谢您分享这么好用的项目!以前用server酱,消息展示不够直观,一直不满意,直到偶尔间看到这个项目,简直太棒了!
我的应用场景是多台机器运行自动化脚本,用来监控异常发出通知,但现在是每台机器都要部署 有点麻烦,如果是可以搭建服务端,只需要在一台机器部署 可以方便很多。可是搭建服务端这块自己不懂,fastapi看了两天没学会……
企微可以上传图片返回url,并在企微内使用https://developer.work.weixin.qq.com/document/path/90256,相当于一个图床工具。
可以解决自建服务器 时常有图床缓存未及时更新的问题,或没有图床的问题
因为众所周知的原因, https://gist.github.com/GentleCP/5d02f4e84b8c8905bcf67643223cd499 这个网址在墙内打不开
能否副本一份墙内友好的地址呢?或者直接放在本git路径下就行吧
谢谢
建议可以建企业微信接收信息的接口一并给写了
当send_text()
方法的touser
参数为空列表[]
时,程序的行为应该是不发送通知。但是实际情况是它会向所有人发送通知,其行为类似@all
。
群机器人发送 运行没有返回错误 但是消息也没法出去
我的clash可以正常访问外网和墙内,但不知道为啥就是corpwechatbot报错,以下是报错信息,
Traceback (most recent call last):
File "urllib3\connectionpool.py", line 696, in urlopen
File "urllib3\connectionpool.py", line 964, in prepare_proxy
File "urllib3\connection.py", line 359, in connect
File "urllib3\connection.py", line 496, in connect_tls_proxy
File "urllib3\util\ssl.py", line 432, in ssl_wrap_socket
File "urllib3\util\ssl.py", line 474, in _ssl_wrap_socket_impl
File "ssl.py", line 500, in wrap_socket
File "ssl.py", line 1040, in _create
File "ssl.py", line 1309, in do_handshake
OSError: [Errno 0] Error
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "requests\adapters.py", line 439, in send
File "urllib3\connectionpool.py", line 755, in urlopen
File "urllib3\util\retry.py", line 573, in increment
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='qyapi.weixin.qq.com', port=443): Max retries exceeded with url: /cgi-bin/gettoken?corpid=*&corpsecret= (Caused by ProxyError('Cannot connect to proxy.', OSError(0, 'Error')))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "任务计划w.py", line 16, in
File "corpwechatbot\app.py", line 57, in init
File "corpwechatbot\app.py", line 62, in __fresh_msg_send_api
File "corpwechatbot\app.py", line 107, in get_assess_token
File "corpwechatbot\app.py", line 111, in __get_access_token
File "requests\api.py", line 76, in get
File "requests\api.py", line 61, in request
File "requests\sessions.py", line 542, in request
File "requests\sessions.py", line 655, in send
File "requests\adapters.py", line 510, in send
requests.exceptions.ProxyError: HTTPSConnectionPool(host='qyapi.weixin.qq.com', port=443): Max retries exceeded with url: /cgi-bin/gettoken?corpid=&corpsecret= (Caused by ProxyError('Cannot connect to proxy.', OSError(0, 'Error')))
类似状态消息,当我不能及时回复内部联系人或外部联系人的消息时,能代替我回复一条状态消息吗
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.