Skip to content

Commit d34f29e

Browse files
committed
Added: Timeout on HTTPS requests
1 parent 266936b commit d34f29e

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

goslideapi/goslideapi.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,17 @@
88

99
# API Link: https://documenter.getpostman.com/view/6223391/S1Lu2pSf
1010
BASEURL = 'https://api.goslide.io/api/{}'
11+
DEFAULT_TIMEOUT = 30
1112

1213

1314
class GoSlideCloud:
1415
"""API Wrapper for the Go Slide devices."""
1516

16-
def __init__(self, username, password):
17+
def __init__(self, username, password, timeout=DEFAULT_TIMEOUT):
1718
"""Create the object with required parameters."""
1819
self._username = username
1920
self._password = password
21+
self._timeout = timeout
2022
self._authenticated = False
2123
self._accesstoken = ''
2224
self._authfailed = False
@@ -35,6 +37,9 @@ async def _dorequest(self, reqtype, urlsuffix, data=None):
3537
_LOGGER.debug("REQ: API=%s, type=%s, data=%s",
3638
BASEURL.format(urlsuffix), reqtype, json.dumps(data))
3739

40+
# Set a reasonable timeout, otherwise it can take > 300 seconds
41+
atimeout = aiohttp.ClientTimeout(total=self._timeout)
42+
3843
# Known error codes from the Cloud API:
3944
# 401 - Authentication failed
4045
# 403 - Forbidden, most likely we want to control a slide
@@ -47,7 +52,8 @@ async def _dorequest(self, reqtype, urlsuffix, data=None):
4752
async with aiohttp.request(reqtype,
4853
BASEURL.format(urlsuffix),
4954
headers=headers,
50-
json=data) as resp:
55+
json=data,
56+
timeout=atimeout) as resp:
5157
if resp.status in [200, 424]:
5258
textdata = await resp.text()
5359
_LOGGER.debug("RES: API=%s, type=%s, HTTPCode=%s, Data=%s",

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
setuptools.setup(
1111
name='goslide-api',
12-
version='0.2.0',
12+
version='0.2.1',
1313
url='https://github.com/ualex73/goslide-api',
1414
license='Apache License 2.0',
1515
author='Alexander Kuiper',

0 commit comments

Comments
 (0)