Skip to content

Commit

Permalink
fix: no timeout for urlopen issue #526
Browse files Browse the repository at this point in the history
  • Loading branch information
grzracz committed Jan 20, 2024
1 parent 3e64019 commit 1e38af4
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
5 changes: 3 additions & 2 deletions algosdk/kmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def __init__(self, kmd_token, kmd_address):
self.kmd_token = kmd_token
self.kmd_address = kmd_address

def kmd_request(self, method, requrl, params=None, data=None):
def kmd_request(self, method, requrl, params=None, data=None, timeout=30):
"""
Execute a given request.
Expand All @@ -35,6 +35,7 @@ def kmd_request(self, method, requrl, params=None, data=None):
requrl (str): url for the request
params (dict, optional): parameters for the request
data (dict, optional): data in the body of the request
timeout (int, optional): request timeout in seconds
Returns:
dict: loaded from json response body
Expand All @@ -56,7 +57,7 @@ def kmd_request(self, method, requrl, params=None, data=None):
)
resp = None
try:
resp = urlopen(req)
resp = urlopen(req, timeout=timeout)
except urllib.error.HTTPError as e:
e = e.read().decode("utf-8")
try:
Expand Down
4 changes: 3 additions & 1 deletion algosdk/v2client/algod.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def algod_request(
data: Optional[bytes] = None,
headers: Optional[Dict[str, str]] = None,
response_format: Optional[str] = "json",
timeout: Optional[int] = 30,
) -> AlgodResponseType:
"""
Execute a given request.
Expand All @@ -72,6 +73,7 @@ def algod_request(
data (bytes, optional): data in the body of the request
headers (dict, optional): additional header for request
response_format (str, optional): format of the response
timeout (int, optional): request timeout in seconds
Returns:
dict loaded from json response body when response_format == "json"
Expand Down Expand Up @@ -101,7 +103,7 @@ def algod_request(
)

try:
resp = urlopen(req)
resp = urlopen(req, timeout=timeout)
except urllib.error.HTTPError as e:
code = e.code
es = e.read().decode("utf-8")
Expand Down
5 changes: 3 additions & 2 deletions algosdk/v2client/indexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def __init__(self, indexer_token, indexer_address, headers=None):
self.headers = headers

def indexer_request(
self, method, requrl, params=None, data=None, headers=None
self, method, requrl, params=None, data=None, headers=None, timeout=30
):
"""
Execute a given request.
Expand All @@ -42,6 +42,7 @@ def indexer_request(
params (dict, optional): parameters for the request
data (dict, optional): data in the body of the request
headers (dict, optional): additional header for request
timeout (int, optional): request timeout in seconds
Returns:
dict: loaded from json response body
Expand Down Expand Up @@ -70,7 +71,7 @@ def indexer_request(
)

try:
resp = urlopen(req)
resp = urlopen(req, timeout=timeout)
except urllib.error.HTTPError as e:
e = e.read().decode("utf-8")
try:
Expand Down

0 comments on commit 1e38af4

Please sign in to comment.