From 0f08ba67e7f0273e80b01df3176052f6e3ef6e77 Mon Sep 17 00:00:00 2001 From: DYefremov Date: Sun, 21 Oct 2018 16:09:57 +0300 Subject: [PATCH] catching connection errors when getting a satellites list --- app/tools/satellites.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/app/tools/satellites.py b/app/tools/satellites.py index 1a995621..21f4f8d6 100644 --- a/app/tools/satellites.py +++ b/app/tools/satellites.py @@ -76,12 +76,17 @@ class SatellitesParser(HTMLParser): self._source = source for src in SatelliteSource.get_sources(self._source): - request = requests.get(url=src, headers=self._HEADERS) - reason = request.reason - if reason == "OK": - self.feed(request.text) + try: + request = requests.get(url=src, headers=self._HEADERS) + except requests.exceptions.ConnectionError as e: + print(repr(e)) + return [] else: - print(reason) + reason = request.reason + if reason == "OK": + self.feed(request.text) + else: + print(reason) if self._rows: if self._source is SatelliteSource.FLYSAT: @@ -197,8 +202,4 @@ class SatellitesParser(HTMLParser): if __name__ == "__main__": - parser = SatellitesParser(source=SatelliteSource.LYNGSAT) - satts = parser.get_satellites_list(SatelliteSource.LYNGSAT) - if satts: - # list(map(print, satts)) - print("Parsed: ", len(satts)) + pass