Skip to content
Open
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
3.9.20
3.10.15
3.11.10
3.12.7
3.13.9
22 changes: 20 additions & 2 deletions botocore/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,16 @@ def _handle_blob(self, shape, text):
class QueryParser(BaseXMLResponseParser):
def _do_error_parse(self, response, shape):
xml_contents = response['body']
root = self._parse_xml_string_to_dom(xml_contents)
try:
root = self._parse_xml_string_to_dom(xml_contents)
except ResponseParserError as e:
status_code = response.get('status_code')
if status_code and status_code in http.client.responses:
status_message = http.client.responses[status_code]
raise ResponseParserError(
f"{str(e)} (HTTP {status_code}: {status_message})"
)
raise
parsed = self._build_name_to_xml_node(root)
self._replace_nodes(parsed)
# Once we've converted xml->dict, we need to make one or two
Expand Down Expand Up @@ -1447,7 +1456,16 @@ def _parse_error_from_http_status(self, response):

def _parse_error_from_body(self, response):
xml_contents = response['body']
root = self._parse_xml_string_to_dom(xml_contents)
try:
root = self._parse_xml_string_to_dom(xml_contents)
except ResponseParserError as e:
status_code = response.get('status_code')
if status_code and status_code in http.client.responses:
status_message = http.client.responses[status_code]
raise ResponseParserError(
f"{str(e)} (HTTP {status_code}: {status_message})"
)
raise
parsed = self._build_name_to_xml_node(root)
self._replace_nodes(parsed)
if root.tag == 'Error':
Expand Down
48 changes: 48 additions & 0 deletions tests/unit/test_parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1621,6 +1621,54 @@ def test_can_parse_route53_with_missing_message(self):
# still populate an empty string.
self.assertEqual(error['Message'], '')

def test_query_parser_empty_body_4xx_error_with_notes(self):
parser = parsers.QueryParser()
response = {
'body': b'',
'headers': {
'Content-Length': '0',
'Date': 'Fri, 21 Nov 2025 18:18:28 GMT',
'Connection': 'close',
},
'status_code': 413,
}

with self.assertRaises(parsers.ResponseParserError) as cm:
parser._do_error_parse(response, None)

exception = cm.exception
self.assertIn("HTTP 413:", str(exception))
error_msg = str(exception)
self.assertTrue(
"Request Entity Too Large" in error_msg
or "Content Too Large" in error_msg,
f"Expected HTTP 413 message not found in: {error_msg}",
)

def test_parse_error_from_body_empty_body_4xx_error_with_notes(self):
parser = parsers.RestXMLParser()
response = {
'body': b'',
'headers': {
'Content-Length': '0',
'Date': 'Fri, 21 Nov 2025 18:18:28 GMT',
'Connection': 'close',
},
'status_code': 413,
}

with self.assertRaises(parsers.ResponseParserError) as cm:
parser._parse_error_from_body(response)

exception = cm.exception
self.assertIn("HTTP 413:", str(exception))
error_msg = str(exception)
self.assertTrue(
"Request Entity Too Large" in error_msg
or "Content Too Large" in error_msg,
f"Expected HTTP 413 message not found in: {error_msg}",
)


def _generic_test_bodies():
generic_html_body = (
Expand Down