Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#1805] Fix xml error #810

Merged
merged 1 commit into from
Oct 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading