Skip to content

Commit a1d5b74

Browse files
committed
fix: move response status check before parsing JSON
1 parent 262b14c commit a1d5b74

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/badfish/main.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -477,15 +477,16 @@ async def get_host_type(self, _interfaces_path):
477477

478478
async def find_session_uri(self):
479479
_response = await self.get_request(self.root_uri, _get_token=True)
480-
raw = await _response.text("utf-8", "ignore")
481-
data = json.loads(raw.strip())
482480

483481
status = _response.status
484482
if status == 401:
485483
raise BadfishException(f"Failed to authenticate. Verify your credentials for {self.host}")
486484
if status not in [200, 201]:
487485
raise BadfishException(f"Failed to communicate with {self.host}")
488486

487+
raw = await _response.text("utf-8", "ignore")
488+
data = json.loads(raw.strip())
489+
489490
redfish_version = int(data["RedfishVersion"].replace(".", ""))
490491
session_uri = None
491492
if redfish_version >= 160:

0 commit comments

Comments
 (0)