Skip to content

Commit

Permalink
Make sure that connection gets closed even if an exception is raised
Browse files Browse the repository at this point in the history
  • Loading branch information
mattrobenolt committed Sep 29, 2014
1 parent 9c89a7d commit 31a5286
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
9 changes: 5 additions & 4 deletions disqusapi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,11 @@ def _request(self, *args, **kwargs):
response = conn.getresponse()

# Coerce response to Python
data = api.formats[format](response.read())

# Close connection
conn.close()
try:
data = api.formats[format](response.read())
finally:
# Close connection
conn.close()

if response.status != 200:
raise ERROR_MAP.get(data['code'], APIError)(data['code'], data['response'])
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def run_tests(self):
author='DISQUS',
author_email='opensource@disqus.com',
url='https://github.com/disqus/disqus-python',
description = 'Disqus API Bindings',
description='Disqus API Bindings',
packages=find_packages(),
zip_safe=False,
test_suite='nose.collector',
Expand Down

0 comments on commit 31a5286

Please sign in to comment.