From 6b6299cd0a3b1b65d5ad31d51d5af30648d9eddd Mon Sep 17 00:00:00 2001 From: profitroll Date: Wed, 4 Jan 2023 10:35:33 +0100 Subject: [PATCH] Added one more check for correct response return --- pyrmv/classes/Client.py | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/pyrmv/classes/Client.py b/pyrmv/classes/Client.py index a8fc61d..a625026 100644 --- a/pyrmv/classes/Client.py +++ b/pyrmv/classes/Client.py @@ -301,8 +301,9 @@ class Client(): find_exception(messages_raw) - for message in messages_raw["Message"]: - messages.append(Message(message)) + if "Message" in messages_raw: + for message in messages_raw["Message"]: + messages.append(Message(message)) return messages @@ -402,11 +403,12 @@ class Client(): find_exception(stops_raw) - for stop in stops_raw["stopLocationOrCoordLocation"]: - if "StopLocation" in stop: - stops.append(Stop(stop["StopLocation"])) - elif "CoordLocation" in stop: - stops.append(Stop(stop["CoordLocation"])) + if "stopLocationOrCoordLocation" in stops_raw: + for stop in stops_raw["stopLocationOrCoordLocation"]: + if "StopLocation" in stop: + stops.append(Stop(stop["StopLocation"])) + elif "CoordLocation" in stop: + stops.append(Stop(stop["CoordLocation"])) return stops @@ -504,11 +506,12 @@ class Client(): find_exception(stops_raw) - for stop in stops_raw["stopLocationOrCoordLocation"]: - if "StopLocation" in stop: - stops.append(Stop(stop["StopLocation"])) - elif "CoordLocation" in stop: - stops.append(Stop(stop["CoordLocation"])) + if "stopLocationOrCoordLocation" in stops_raw: + for stop in stops_raw["stopLocationOrCoordLocation"]: + if "StopLocation" in stop: + stops.append(Stop(stop["StopLocation"])) + elif "CoordLocation" in stop: + stops.append(Stop(stop["CoordLocation"])) return stops @@ -697,8 +700,9 @@ class Client(): find_exception(trips_raw) - for trip in trips_raw["Trip"]: - trips.append(Trip(trip)) + if "Trip" in trips_raw: + for trip in trips_raw["Trip"]: + trips.append(Trip(trip)) return trips @@ -770,7 +774,8 @@ class Client(): find_exception(trips_raw) - for trip in trips_raw["Trip"]: - trips.append(Trip(trip)) + if "Trip" in trips_raw: + for trip in trips_raw["Trip"]: + trips.append(Trip(trip)) return trips \ No newline at end of file