Skip to content

Commit 18b23e4

Browse files
authored
Merge pull request #171 from DMTF/Fix170-Empty-Response-Handling
Updated 'dict' handling for responses without a body to use an empty dictionary
2 parents ad73ed1 + 1a40282 commit 18b23e4

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

src/redfish/rest/v1.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,16 @@ def text(self, value):
249249
def dict(self):
250250
"""Property for accessing the data as an dict"""
251251
try:
252+
if len(self.text) == 0:
253+
# No response body; return empty dict instead to avoid exceptions
254+
# No response bodies can be valid in many cases (especially 4XX and 5XX responses)
255+
return {}
252256
return json.loads(self.text)
253257
except:
258+
if self.status == 500:
259+
# Make an allowance for 500 status codes
260+
# Depending on the reason for the error, it's possible the web server may not be able to support Redfish handling
261+
return {}
254262
str = "Service responded with invalid JSON at URI {}\n{}".format(
255263
self._rest_request.path, self.text)
256264
LOGGER.error(str)

0 commit comments

Comments
 (0)