Skip to content

Commit

Permalink
lib.web: fix error handling for aiohttp 2.0.
Browse files Browse the repository at this point in the history
Fixes:

    AttributeError: module 'aiohttp' has no attribute 'errors'

aio-libs/aiohttp#1753
  • Loading branch information
jwilk committed Mar 25, 2017
1 parent 4c6114c commit e18179c
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions lib/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@

import aiohttp

aiohttp_major_ver = int(aiohttp.__version__.split('.', 1)[0])
if aiohttp_major_ver >= 2:
misc_aiohttp_errors = ()
else:
misc_aiohttp_errors = (
aiohttp.errors.DisconnectedError,
aiohttp.errors.HttpProcessingError,
)

user_agent = 'urlycue (https://github.com/jwilk/urlycue)'
http_headers = {'User-Agent': user_agent}
redirect_limit = 10
Expand Down Expand Up @@ -117,7 +126,7 @@ async def check_url(url, check_cert=True):
try:
async with aiohttp.client.ClientSession(connector=connector, headers=http_headers) as session:
status = await _check_url(session, url)
except aiohttp.errors.ClientOSError as exc:
except aiohttp.ClientOSError as exc:
rexc = exc
while rexc is not None:
if isinstance(rexc, ssl.SSLError):
Expand All @@ -126,11 +135,9 @@ async def check_url(url, check_cert=True):
status = rexc or exc
except ssl.CertificateError as exc:
status = exc
except aiohttp.errors.ClientError as exc:
status = exc
except aiohttp.errors.DisconnectedError as exc:
except aiohttp.ClientError as exc:
status = exc
except aiohttp.errors.HttpProcessingError as exc:
except misc_aiohttp_errors as exc:
status = exc
_url_cache[url] = status
logger.debug('done {}'.format(url))
Expand Down

0 comments on commit e18179c

Please sign in to comment.