From cc01d87209269fda478196fdb7ee43ce6a573756 Mon Sep 17 00:00:00 2001 From: Adrian Sampson Date: Tue, 3 Feb 2015 23:04:14 -0800 Subject: [PATCH] discogs: Catch *another* exception (fix #1305) Everything but requests is a travesty. --- beetsplug/discogs.py | 10 +++++++--- docs/changelog.rst | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/beetsplug/discogs.py b/beetsplug/discogs.py index 2ba2fdd6f..a3239963b 100644 --- a/beetsplug/discogs.py +++ b/beetsplug/discogs.py @@ -31,6 +31,7 @@ import re import time import json import socket +import httplib # Silence spurious INFO log lines generated by urllib3. @@ -39,6 +40,9 @@ urllib3_logger.setLevel(logging.CRITICAL) USER_AGENT = u'beets/{0} +http://beets.radbox.org/'.format(beets.__version__) +# Exceptions that discogs_client should really handle but does not. +CONNECTION_ERRORS = ConnectionError, socket.error, httplib.HTTPException + class DiscogsPlugin(BeetsPlugin): @@ -91,7 +95,7 @@ class DiscogsPlugin(BeetsPlugin): token, secret = auth_client.get_access_token(code) except DiscogsAPIError: raise beets.ui.UserError('Discogs authorization failed') - except (ConnectionError, socket.error) as e: + except CONNECTION_ERRORS as e: self._log.debug(u'connection error: {0}', e) raise beets.ui.UserError('communication with Discogs failed') @@ -126,7 +130,7 @@ class DiscogsPlugin(BeetsPlugin): except DiscogsAPIError as e: self._log.debug(u'API Error: {0} (query: {1})', e, query) return [] - except (ConnectionError, socket.error) as e: + except CONNECTION_ERRORS as e: self._log.debug(u'HTTP Connection Error: {0}', e) return [] @@ -154,7 +158,7 @@ class DiscogsPlugin(BeetsPlugin): if e.message != '404 Not Found': self._log.debug(u'API Error: {0} (query: {1})', e, result._uri) return None - except ConnectionError as e: + except CONNECTION_ERRORS as e: self._log.debug(u'HTTP Connection Error: {0}', e) return None return self.get_album_info(result) diff --git a/docs/changelog.rst b/docs/changelog.rst index e8473d7c5..81493428c 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -100,7 +100,7 @@ Fixes: scrub`` command cannot write a file. Also, avoid problems on Windows with Unicode filenames. :bug:`1297` * :doc:`/plugins/discogs`: Handle and log more kinds of communication - errors. :bug:`1299` + errors. :bug:`1299` :bug:`1305` For developers: