def get_status_xml(self, command):
"""Get status XML via HTTP and return it as XML ElementTree."""
# Get XML structure via HTTP get
res = requests.get("http://{host}{command}".format(
host=self._host, command=command), timeout=self.timeout)
# Continue with XML processing only if HTTP status code = 200
if res.status_code == 200:
try:
# Return XML ElementTree
return ET.fromstring(res.text)
except ET.ParseError:
_LOGGER.error(
"Host %s returned malformed XML for: %s",
self._host, command)
raise ValueError
else:
_LOGGER.error((
"Host %s returned HTTP status code %s "
"when trying to receive data"), self._host, res.status_code)
raise ValueError
评论列表
文章目录