From 7e7a85988d8c3c8da20dd1032cc23d8532bdaeb4 Mon Sep 17 00:00:00 2001 From: Dave Bacon Date: Thu, 20 May 2021 08:04:39 -0700 Subject: [PATCH 1/2] Add default timeout to requests --- pennylane_ionq/api_client.py | 5 +++++ tests/test_api_client.py | 1 + 2 files changed, 6 insertions(+) diff --git a/pennylane_ionq/api_client.py b/pennylane_ionq/api_client.py index 9c09812..b653068 100644 --- a/pennylane_ionq/api_client.py +++ b/pennylane_ionq/api_client.py @@ -129,6 +129,9 @@ def __init__(self, **kwargs): self.HEADERS = {"User-Agent": self.USER_AGENT} + # Ten minute timout on requests. + self.TIMEOUT_SECONDS = 60 * 10 + if self.AUTHENTICATION_TOKEN: self.set_authorization_header(self.AUTHENTICATION_TOKEN) else: @@ -179,6 +182,8 @@ def request(self, method, **params): params["headers"] = self.HEADERS + params["timeout"] = self.TIMEOUT_SECONDS + try: response = method(**params) except Exception as e: diff --git a/tests/test_api_client.py b/tests/test_api_client.py index d317712..6a82c06 100755 --- a/tests/test_api_client.py +++ b/tests/test_api_client.py @@ -113,6 +113,7 @@ def test_init_default_client(self): client = api_client.APIClient(authentication_token="") assert client.BASE_URL.startswith("https://") assert client.HEADERS["User-Agent"] == client.USER_AGENT + assert client.TIMEOUT_SECONDS == 600 def test_set_authorization_header(self): """ From 963898df99796e64a39562675935b8077c768e0e Mon Sep 17 00:00:00 2001 From: Dave Bacon Date: Thu, 20 May 2021 09:21:10 -0700 Subject: [PATCH 2/2] typppo --- pennylane_ionq/api_client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pennylane_ionq/api_client.py b/pennylane_ionq/api_client.py index b653068..08f9365 100644 --- a/pennylane_ionq/api_client.py +++ b/pennylane_ionq/api_client.py @@ -129,7 +129,7 @@ def __init__(self, **kwargs): self.HEADERS = {"User-Agent": self.USER_AGENT} - # Ten minute timout on requests. + # Ten minute timeout on requests. self.TIMEOUT_SECONDS = 60 * 10 if self.AUTHENTICATION_TOKEN: