Skip to content

Commit 52fccfa

Browse files
committed
feat: add request timeout with 30-second default
Prevent indefinite blocking when the server is unresponsive by passing a timeout to urllib.request.urlopen. Defaults to 30 seconds; set to None to disable. BREAKING CHANGE: requests now time out after 30 seconds by default
1 parent afa63b2 commit 52fccfa

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

kanboard.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ def __init__(
6363
insecure: bool = False,
6464
ignore_hostname_verification: bool = False,
6565
user_agent: str = "Kanboard Python API Client",
66+
timeout: Optional[int] = 30,
6667
loop: Optional[asyncio.AbstractEventLoop] = None,
6768
) -> None:
6869
"""
@@ -81,6 +82,7 @@ def __init__(
8182
Defaults to False.
8283
user_agent (str, optional): Custom User-Agent string for HTTP requests. Defaults to
8384
'Kanboard Python API Client'.
85+
timeout (Optional[int], optional): Request timeout in seconds. Defaults to 30. Set to None to disable.
8486
loop (Optional[asyncio.AbstractEventLoop], optional): Asyncio event loop to use. If None, uses the
8587
current event loop or creates a new one.
8688
"""
@@ -91,6 +93,7 @@ def __init__(
9193
self._cafile = cafile
9294
self._insecure = insecure
9395
self._user_agent = user_agent
96+
self._timeout = timeout
9497
self._ignore_hostname_verification = ignore_hostname_verification
9598

9699
if not loop:
@@ -160,7 +163,7 @@ def _do_request(self, headers: Dict[str, str], body: Dict[str, Any]) -> Any:
160163
if self._ignore_hostname_verification:
161164
ssl_context.check_hostname = False
162165

163-
response = http.urlopen(request, context=ssl_context).read()
166+
response = http.urlopen(request, context=ssl_context, timeout=self._timeout).read()
164167
except Exception as e:
165168
raise ClientError(str(e))
166169
return self._parse_response(response)

0 commit comments

Comments
 (0)