10000 Quick Fix for NonXMLErrorException (#515) · rmagier1/server-client-python@ba2796f · GitHub
[go: up one dir, main page]

Skip to content

Commit ba2796f

Browse files
authored
Quick Fix for NonXMLErrorException (tableau#515)
Catch ParseError's and pass the response body up though the stack. Partially addresses tableau#514
1 parent fe3ac07 commit ba2796f

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

tableauserverclient/server/endpoint/endpoint.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from .exceptions import ServerResponseError, InternalServerError
1+
from .exceptions import ServerResponseError, InternalServerError, NonXMLResponseError
22
from functools import wraps
33
from xml.etree.ElementTree import ParseError
44

@@ -69,8 +69,14 @@ def _check_status(self, server_response):
6969
try:
7070
raise ServerResponseError.from_response(server_response.content, self.parent_srv.namespace)
7171
except ParseError:
72-
# not an xml error
72+
# This will happen if we get a non-success HTTP code that
73+
# doesn't return an xml error object (like metadata endpoints)
74+
# we convert this to a better exception and pass through the raw
75+
# response body
7376
raise NonXMLResponseError(server_response.content)
77+
except Exception as e:
78+
# anything else re-raise here
79+
raise
7480

7581
def get_unauthenticated_request(self, url, request_object=None):
7682
return self._make_request(self.parent_srv.session.get, url, request_object=request_object)

test/test_requests.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import tableauserverclient as TSC
77

8-
from tableauserverclient.server.endpoint.exceptions import InternalServerError
8+
from tableauserverclient.server.endpoint.exceptions import InternalServerError, NonXMLResponseError
99

1010

1111
class RequestTests(unittest.TestCase):
@@ -55,3 +55,11 @@ def test_internal_server_error(self):
5555
with requests_mock.mock() as m:
5656
m.register_uri('GET', self.server.server_info.baseurl, status_code=500, text=server_response)
5757
self.assertRaisesRegexp(InternalServerError, server_response, self.server.server_info.get)
58+
59+
# Test that non-xml server errors are handled properly
60+
def test_non_xml_error(self):
61+
self.server.version = "3.2"
62+
server_response = "this is not xml"
63+
with requests_mock.mock() as m:
64+
m.register_uri('GET', self.server.server_info.baseurl, status_code=499, text=server_response)
65+
self.assertRaisesRegexp(NonXMLResponseError, server_response, self.server.server_info.get)

0 commit comments

Comments
 (0)
0