From fc1715b8d7267939909cd93f29cb43e48e422db5 Mon Sep 17 00:00:00 2001 From: 42kun Date: Tue, 24 Oct 2023 11:50:55 +0800 Subject: [PATCH] bugfix: corrected XML parsing error --- setup.py | 1 + werobot/client.py | 4 ++-- werobot/parser.py | 4 +++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/setup.py b/setup.py index 1e7c3b5c..60814a5e 100755 --- a/setup.py +++ b/setup.py @@ -6,6 +6,7 @@ from setuptools import setup, find_packages from setuptools.command.test import test as TestCommand +import sys class PyTest(TestCommand): diff --git a/werobot/client.py b/werobot/client.py index 2d0edae6..82045453 100644 --- a/werobot/client.py +++ b/werobot/client.py @@ -52,6 +52,7 @@ class Client(object): 微信 API 操作类 通过这个类可以方便的通过微信 API 进行一系列操作,比如主动发送消息、创建自定义菜单等 """ + def __init__(self, config): self.config = config self._token = None @@ -357,8 +358,7 @@ def upload_custom_service_account_avatar(self, account, avatar): :return: 返回的 JSON 数据包 """ return self.post( - url= - "http://api.weixin.qq.com/customservice/kfaccount/uploadheadimg", + url="http://api.weixin.qq.com/customservice/kfaccount/uploadheadimg", params={ "access_token": self.token, "kf_account": account diff --git a/werobot/parser.py b/werobot/parser.py index 23720f90..01341dc3 100644 --- a/werobot/parser.py +++ b/werobot/parser.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- +import re import xmltodict from werobot.messages.messages import MessageMetaClass, UnknownMessage from werobot.messages.events import EventMetaClass, UnknownEvent @@ -11,7 +12,8 @@ def parse_user_msg(xml): def parse_xml(text): - xml_dict = xmltodict.parse(text)["xml"] + text_clean = re.sub(b'[\x00-\x09\x0B-\x0C\x0E-\x1F]', b'', text) + xml_dict = xmltodict.parse(text_clean)["xml"] xml_dict["raw"] = text return xml_dict