[whyour/qinglong]经过测试 notify.py企业微信的调用还是存在问题

2024-01-10 888 views
1
Qinglong version

2.16.1

Steps to reproduce

调用notify.py发送消息,其他通道正常,企业微信应用消息无法推送,好像是代理地址这一块有问题,我的应用建立时间比较早,不需要代理也能推送

What is expected?

应该是正常推送,在2.15版本的时候应该没出现过这个问题

What is actually happening?

企业微信 APP 服务启动 Exception in thread wecom_app: Traceback (most recent call last): File "/usr/local/lib/python3.10/threading.py", line 1016, in _bootstrap_inner self.run() File "/usr/local/lib/python3.10/threading.py", line 953, in run self._target(*self._args, self._kwargs) File "/ql/data/scripts/share/notify.py", line 417, in wecom_app response = wx.send_mpnews(title, content, media_id, touser) File "/ql/data/scripts/share/notify.py", line 459, in send_mpnews send_url = f"https://{self.ORIGIN}/cgi-bin/message/send?access_token={self.get_access_token()}" File "/ql/data/scripts/share/notify.py", line 440, in get_access_token req = requests.post(url, params=values) File "/usr/local/lib/python3.10/site-packages/requests/api.py", line 117, in post return request('post', url, data=data, json=json, kwargs) File "/usr/local/lib/python3.10/site-packages/requests/api.py", line 61, in request return session.request(method=method, url=url, **kwargs) File "/usr/local/lib/python3.10/site-packages/requests/sessions.py", line 515, in request prep = self.prepare_request(req) File "/usr/local/lib/python3.10/site-packages/requests/sessions.py", line 443, in prepare_request p.prepare( File "/usr/local/lib/python3.10/site-packages/requests/models.py", line 318, in prepare self.prepare_url(url, params) File "/usr/local/lib/python3.10/site-packages/requests/models.py", line 392, in prepare_url raise MissingSchema(error) requests.exceptions.MissingSchema: Invalid URL '127.0.0.1/cgi-bin/gettoken': No scheme supplied. Perhaps you meant http://127.0.0.1/cgi-bin/gettoken?

System Info
Need to install the following packages:
envinfo@7.10.0
Ok to proceed? (y) 

  System:
    OS: Linux 5.4 Alpine Linux
    CPU: (4) x64 Intel(R) Celeron(R) CPU N3450 @ 1.10GHz
    Memory: 4.88 GB / 7.62 GB
    Container: Yes
    Shell: 5.2.15 - /bin/bash
  Binaries:
    Node: 18.17.0 - /usr/bin/node
    npm: 9.8.1 - /usr/local/bin/npm
    pnpm: 8.3.1 - /usr/local/bin/pnpm
  Browsers:
    Chromium: 115.0.5790.170

回答

3

QYWX_ORIGIN 要以http开头,你这咋配置的,不需要就把变量删掉

8

image 这是注释掉变量后的推送日志

3

`class WeCom: def init(self, corpid, corpsecret, agentid): self.CORPID = corpid self.CORPSECRET = corpsecret self.AGENTID = agentid self.ORIGIN = "https://qyapi.weixin.qq.com" if push_config.get("QYWX_ORIGIN"): self.ORIGIN = push_config.get("QYWX_ORIGIN")

def get_access_token(self):
    url = f"{self.ORIGIN}/cgi-bin/gettoken"
    values = {
        "corpid": self.CORPID,
        "corpsecret": self.CORPSECRET,
    }
    req = requests.post(url, params=values)
    data = json.loads(req.text)
    return data["access_token"]

def send_text(self, message, touser="@all"):
    send_url = f"{self.ORIGIN}/cgi-bin/message/send?access_token={self.get_access_token()}"
    send_values = {
        "touser": touser,
        "msgtype": "text",
        "agentid": self.AGENTID,
        "text": {"content": message},
        "safe": "0",
    }
    send_msges = bytes(json.dumps(send_values), "utf-8")
    respone = requests.post(send_url, send_msges)
    respone = respone.json()
    return respone["errmsg"]

def send_mpnews(self, title, message, media_id, touser="@all"):
    send_url = f"https://{self.ORIGIN}/cgi-bin/message/send?access_token={self.get_access_token()}"
    send_values = {
        "touser": touser,
        "msgtype": "mpnews",
        "agentid": self.AGENTID,
        "mpnews": {
            "articles": [
                {
                    "title": title,
                    "thumb_media_id": media_id,
                    "author": "Author",
                    "content_source_url": "",
                    "content": message.replace("\n", "<br/>"),
                    "digest": message,
                }
            ]
        },
    }
    send_msges = bytes(json.dumps(send_values), "utf-8")
    respone = requests.post(send_url, send_msges)
    respone = respone.json()
    return respone["errmsg"]`

问题可能在这一段,我把5月份的notify.py文件同一位置的代码替换过来后就可以推送了 image

9

环境变量有缓存,重启下应该就行了

8

找到问题了,notify.py文件第459行多写了一个前缀 image