diff --git a/owslib/util.py b/owslib/util.py index 3165b484..12c73400 100644 --- a/owslib/util.py +++ b/owslib/util.py @@ -346,8 +346,10 @@ def getXMLTree(rsp: ResponseWrapper) -> etree: content_type = rsp.info().get('Content-Type', 'text/xml') url = rsp.geturl() + has_xml_tag = raw_text.lstrip().startswith(b' 0: response_text = html_body.text.strip("\n") diff --git a/tests/test_util.py b/tests/test_util.py index 7bccee26..4db76189 100644 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -71,6 +71,20 @@ def test_getXMLTree_valid(): assert et.find('.//Title').text == "Example" +def test_getXMLTree_non_xml_mime_type(): + + mock_resp = mock.Mock() + mock_resp.url = 'http:///example.org/?service=WFS&request=GetCapabilities&version=2.0.0' + mock_resp.content = b'\n' \ + b'Example' + # test with a non-XML mime type, but the response starts with