Skip to content

Commit 03a8d44

Browse files
authored
Merge pull request #156 from rackerlabs/issue-155-update-api-client-function-retrieve_scan_results
Improved logic for API client retrieve_scan_results()
2 parents 7a26649 + c6e4661 commit 03a8d44

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

scantron_api_client/scantron_api_client.py

+10-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
# Custom Python libraries.
1010
import utility
1111

12-
__version__ = "1.0"
12+
__version__ = "1.1"
1313

1414

1515
class ScantronClient:
@@ -199,15 +199,21 @@ def scantron_api_query(self, endpoint, **kwargs):
199199
# Scan Results
200200
##############
201201
def retrieve_scan_results(self, scan_id, file_type, **kwargs):
202-
"""Returns a text blob of the scan results. For .json files, you can convert it to a Python JSON object using:
202+
"""Returns a text blob of the scan results if they actually exist. For .json files, you can convert it to a
203+
Python JSON object using:
203204
scan_results_json = json.loads(scan_results)"""
204205

206+
scan_results = None
207+
205208
if file_type.lower() not in ["nmap", "xml", "json"]:
206209
print(f"Not a valid file type: {file_type}")
207-
scan_results = None
208210

209211
else:
210-
scan_results = self.scantron_api_query(f"/results/{scan_id}?file_type={file_type}", **kwargs).text
212+
response = self.scantron_api_query(f"/results/{scan_id}?file_type={file_type}", **kwargs)
213+
214+
# Only return the results if they actually exist.
215+
if response.status_code == 200:
216+
scan_results = response.text
211217

212218
return scan_results
213219

0 commit comments

Comments
 (0)