Add optional timeout to API, 60s default

This commit is contained in:
Cyber MacGeddon 2025-05-08 18:59:41 +01:00
parent 9e9b21068c
commit 7feb825887

View file

@ -25,7 +25,7 @@ def check_error(response):
class Api: class Api:
def __init__(self, url="http://localhost:8088/"): def __init__(self, url="http://localhost:8088/", timeout=60):
self.url = url self.url = url
@ -34,6 +34,8 @@ class Api:
self.url += "api/v1/" self.url += "api/v1/"
self.timeout = timeout
def flow(self): def flow(self):
return Flow(api=self) return Flow(api=self)
@ -51,7 +53,7 @@ class Api:
# print(json.dumps(request, indent=4)) # print(json.dumps(request, indent=4))
# Invoke the API, input is passed as JSON # Invoke the API, input is passed as JSON
resp = requests.post(url, json=request) resp = requests.post(url, json=request, timeout=self.timeout)
# Should be a 200 status code # Should be a 200 status code
if resp.status_code != 200: if resp.status_code != 200: