Catch invalid XML in suggestion response

As reported in #593, the XML response body returned for search
suggestions can apparently contain invalid XML elements. This catches
the error and returns an empty suggestion list instead of erroring.

Fixes #593
pull/604/head
Ben Busby 2 years ago
parent 362b6a75c8
commit f4b65be876
No known key found for this signature in database
GPG Key ID: B9B7231E01D924A1

@ -229,9 +229,13 @@ class Request:
if not response:
return []
root = ET.fromstring(response)
return [_.attrib['data'] for _ in
root.findall('.//suggestion/[@data]')]
try:
root = ET.fromstring(response)
return [_.attrib['data'] for _ in
root.findall('.//suggestion/[@data]')]
except ET.ParseError:
# Malformed XML response
return []
def send(self, base_url='', query='', attempt=0,
force_mobile=False) -> Response:

Loading…
Cancel
Save