Skip to content

Commit

Permalink
Close session even if there's an exception
Browse files Browse the repository at this point in the history
  • Loading branch information
john-kurkowski committed Oct 26, 2017
1 parent f3ddeda commit 9385150
Showing 1 changed file with 13 additions and 17 deletions.
30 changes: 13 additions & 17 deletions tldextract/remote.py
Expand Up @@ -28,23 +28,19 @@ def find_first_response(urls, cache_fetch_timeout=None):
""" Decode the first successfully fetched URL, from UTF-8 encoding to
Python unicode.
"""
text = ''

session = requests.Session()
session.mount('file://', FileAdapter())

for url in urls:
try:
text = session.get(url, timeout=cache_fetch_timeout).text
except requests.exceptions.RequestException:
LOG.exception(
'Exception reading Public Suffix List url %s',
url
)
else:
ans = _decode_utf8(text)
session.close()
return ans
with requests.Session() as session:
session.mount('file://', FileAdapter())

for url in urls:
try:
text = session.get(url, timeout=cache_fetch_timeout).text
except requests.exceptions.RequestException:
LOG.exception(
'Exception reading Public Suffix List url %s',
url
)
else:
return _decode_utf8(text)

LOG.error(
'No Public Suffix List found. Consider using a mirror or constructing '
Expand Down

0 comments on commit 9385150

Please sign in to comment.