huawei-modem-python-api-client icon indicating copy to clipboard operation
huawei-modem-python-api-client copied to clipboard

MMS Message causes program to crash

Open christheradioguy opened this issue 3 years ago • 0 comments

I've noticed when MMS messages are received, the program crashes with

Traceback (most recent call last):
  File "huaweiApi.py", line 52, in <module>
    latestMessage=huaweisms.api.sms.get_sms(ctx,1,1,1)
  File "/home/christopher/.local/lib/python3.8/site-packages/huaweisms/api/sms.py", line 39, in get_sms
    r = post_to_url(url, xml_data, ctx, headers)
  File "/home/christopher/.local/lib/python3.8/site-packages/huaweisms/api/common.py", line 114, in post_to_url
    return api_response(r)
  File "/home/christopher/.local/lib/python3.8/site-packages/huaweisms/api/common.py", line 74, in api_response
    xmldoc = parse_xml_string(r.text.encode('ascii','ignore').decode('utf-8'))
  File "/home/christopher/.local/lib/python3.8/site-packages/huaweisms/xml/util.py", line 62, in parse_xml_string
    return minidom.parseString(parseable_xml_string)
  File "/usr/lib/python3.8/xml/dom/minidom.py", line 1969, in parseString
    return expatbuilder.parseString(string)
  File "/usr/lib/python3.8/xml/dom/expatbuilder.py", line 925, in parseString
    return builder.parseString(string)
  File "/usr/lib/python3.8/xml/dom/expatbuilder.py", line 223, in parseString
    parser.Parse(string, True)
xml.parsers.expat.ExpatError: not well-formed (invalid token): line 9, column 12

I did a bit of investigation, and it seems that when an MMS message is received by the Huawei device, the API returns invalid characters. I made a really hacky fix by changing the following line in api/common.py: xmldoc = parse_xml_string(r.text) to xmldoc = parse_xml_string(r.text.encode('ascii','ignore').decode('utf-8').replace("\x01\x06\x08\x01","")) in order to remove the invalid characters, but I'm sure a better solution is out there.

The device is a Huawei B315 if it makes any difference.

christheradioguy avatar Apr 09 '22 17:04 christheradioguy