Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated 'dict' handling for responses without a body to use an empty dictionary #171

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
8 changes: 8 additions & 0 deletions src/redfish/rest/v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,16 @@ def text(self, value):
def dict(self):
"""Property for accessing the data as an dict"""
try:
if len(self.text) == 0:
# No response body; return empty dict instead to avoid exceptions
# No response bodies can be valid in many cases (especially 4XX and 5XX responses)
return {}
return json.loads(self.text)
except:
if self.status == 500:
# Make an allowance for 500 status codes
# Depending on the reason for the error, it's possible the web server may not be able to support Redfish handling
return {}
str = "Service responded with invalid JSON at URI {}\n{}".format(
self._rest_request.path, self.text)
LOGGER.error(str)
Expand Down