Skip to content

Commit

Permalink
Merge pull request #810 from maykinmedia/fix/1805-xml-error
Browse files Browse the repository at this point in the history
[#1805] Fix xml error
  • Loading branch information
alextreme authored Oct 13, 2023
2 parents 5a60c3e + 60821e4 commit 037b68f
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/open_inwoner/ssd/xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import requests
from lxml import etree # nosec
from lxml.etree import LxmlError # nosec
from xsdata.exceptions import ParserError
from xsdata.formats.dataclass.context import XmlContext
from xsdata.formats.dataclass.parsers import XmlParser
Expand Down Expand Up @@ -41,14 +42,19 @@ def _get_report_info(
if not response.content:
return None

tree = etree.fromstring(response.content)
node = tree.find(info_response_node)
try:
tree = etree.fromstring(response.content).getroottree()
node = tree.find(info_response_node)
except LxmlError:
return None

parser = XmlParser(context=XmlContext(), handler=LxmlEventHandler)

try:
info = parser.parse(node, info_type)
except ParserError:
return None

return info


Expand Down

0 comments on commit 037b68f

Please sign in to comment.