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
main
Ben Busby 2021-12-28 11:38:18 -07:00
parent 362b6a75c8
commit f4b65be876
No known key found for this signature in database
GPG Key ID: B9B7231E01D924A1
1 changed files with 7 additions and 3 deletions

View File

@ -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: