From 2a2e92f3127f31ca2244601f30d4134474cc1f11 Mon Sep 17 00:00:00 2001 From: Josh Date: Mon, 1 Apr 2019 14:16:49 -0400 Subject: [PATCH 1/3] added timeouts --- penn/studyspaces.py | 6 ++++-- penn/wharton.py | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/penn/studyspaces.py b/penn/studyspaces.py index 9daa250..d30e571 100644 --- a/penn/studyspaces.py +++ b/penn/studyspaces.py @@ -239,16 +239,18 @@ def cancel_room(self, booking_id): resp = self._request("POST", "/1.1/space/cancel/{}".format(booking_id)) return resp.json() - def get_reservations(self, email, date): + def get_reservations(self, email, date, timeout=None): """Gets reservations for a given email. :param email: the email of the user who's reservations are to be fetched :type email: str """ try: - resp = self._request("GET", "/1.1/space/bookings?email={}&date={}&limit=100".format(email, date)) + resp = self._request("GET", "/1.1/space/bookings?email={}&date={}&limit=100".format(email, date), timeout=timeout) except resp.exceptions.HTTPError as error: raise APIError("Server Error: {}".format(error)) + except requests.exceptions.ConnectTimeout as error: + raise APIError("Timeout Error") return resp.json() def get_reservations_for_booking_ids(self, booking_ids): diff --git a/penn/wharton.py b/penn/wharton.py index 6f6f23d..8070d7c 100644 --- a/penn/wharton.py +++ b/penn/wharton.py @@ -18,15 +18,17 @@ class Wharton(object): >>> s = Wharton() """ - def get_reservations(self, sessionid): + def get_reservations(self, sessionid, timeout=None): """Returns a list of location IDs and names.""" url = "{}{}".format(BASE_URL, "/reservations/") cookies = dict(sessionid=sessionid) try: - resp = requests.get(url, cookies=cookies) + resp = requests.get(url, timeout=timeout, cookies=cookies) except resp.exceptions.HTTPError as error: raise APIError("Server Error: {}".format(error)) + except requests.exceptions.ConnectTimeout: + raise APIError("Timeout Error") html = resp.content.decode("utf8") From cca48208b75b78bb8e0b164a45472d00b469cad1 Mon Sep 17 00:00:00 2001 From: Josh Date: Mon, 1 Apr 2019 14:17:24 -0400 Subject: [PATCH 2/3] updated version --- penn/__init__.py | 2 +- setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/penn/__init__.py b/penn/__init__.py index e4ecf3a..2309629 100644 --- a/penn/__init__.py +++ b/penn/__init__.py @@ -1,4 +1,4 @@ -__version__ = '1.8.3' +__version__ = '1.8.4' from .registrar import Registrar from .directory import Directory diff --git a/setup.py b/setup.py index 3a6e6f0..1e57163 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ url='https://github.com/pennlabs/penn-sdk-python', author='Penn Labs', author_email='admin@pennlabs.org', - version='1.8.3', + version='1.8.4', packages=['penn'], license='MIT', package_data={ From 1626502bc4bdea5c5dcf9b926ab1fbff7b983ead Mon Sep 17 00:00:00 2001 From: Josh Date: Mon, 1 Apr 2019 14:26:47 -0400 Subject: [PATCH 3/3] fixed flake error --- penn/studyspaces.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/penn/studyspaces.py b/penn/studyspaces.py index d30e571..38b6d12 100644 --- a/penn/studyspaces.py +++ b/penn/studyspaces.py @@ -249,7 +249,7 @@ def get_reservations(self, email, date, timeout=None): resp = self._request("GET", "/1.1/space/bookings?email={}&date={}&limit=100".format(email, date), timeout=timeout) except resp.exceptions.HTTPError as error: raise APIError("Server Error: {}".format(error)) - except requests.exceptions.ConnectTimeout as error: + except requests.exceptions.ConnectTimeout: raise APIError("Timeout Error") return resp.json()