From ab037a07650aeee638961fc23c085370c5cb9889 Mon Sep 17 00:00:00 2001 From: anthonybaxter Date: Tue, 6 Jul 2021 11:50:12 +1000 Subject: [PATCH] Add a warning if a server sends back non-XML https://data.csiro.au/dap/ws/v2/collections is an example of a server that sends back JSON rather than XML to a sickle request by default. Adding headers={'Accept': 'application/xml'} to the Sickle() constructor fixes that, but it was a bit of digging to work out why. This logging message would have saved me a bit of debugging time. --- sickle/response.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/sickle/response.py b/sickle/response.py index 76f6897..af07365 100644 --- a/sickle/response.py +++ b/sickle/response.py @@ -6,6 +6,7 @@ :copyright: Copyright 2015 Mathias Loesch """ +import logging from lxml import etree XMLParser = etree.XMLParser(remove_blank_text=True, recover=True, resolve_entities=False) @@ -34,6 +35,10 @@ def raw(self): @property def xml(self): """The server's response as parsed XML.""" + if (self.http_response.headers.get('Content-Type') != + 'application/xml'): + logging.warn('received non-XML response %s', + self.http_response.headers.get('Content-Type')) return etree.XML(self.http_response.content, parser=XMLParser)