From 88edc2d0f25ad6c3e0335affacb8c1e92b032d2e Mon Sep 17 00:00:00 2001 From: schneefux Date: Wed, 15 Feb 2017 15:13:16 +0100 Subject: ignore server errors --- crawler.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'crawler.py') diff --git a/crawler.py b/crawler.py index aa0d029..f988375 100644 --- a/crawler.py +++ b/crawler.py @@ -1,6 +1,7 @@ #!/usr/bin/python import asyncio +import logging import aiohttp TOKEN = "aaa.bbb.ccc" @@ -32,10 +33,14 @@ class Crawler(object): "Accept": "application/vnd.api+json", "Content-Encoding": "gzip" } - async with session.get(self._apiurl + path, headers=headers, - params=params) as response: - assert response.status == 200 - return await response.json() + try: + async with session.get(self._apiurl + path, headers=headers, + params=params) as response: + assert response.status == 200 + return await response.json() + except aiohttp.errors.ClientResponseError: + logging.warning("error connecting to API, retrying") + return await self._req(session, path, params) async def version(self): """Returns the current API version.""" -- cgit v1.3.1