Repository: pymedusa/Medusa

Issue:
[APP SUBMITTED]: HTTPError: 503 Server Error: Service Unavailable: Back-end server is at capacity for url: https://api.themoviedb.org/3/tv/changes?api_key=**********&start_date=2017-08-28&end_date=2017-09-11&page=3
### INFO
**Python Version**: `2.7.9 (default, Jun 29 2016, 13:08:31) [GCC 4.9.2]`
**Operating System**: `Linux-3.16.0-4-amd64-x86_64-with-debian-8.8`
**Locale**: `UTF-8`
**Branch**: [develop](../tree/develop)
**Database**: `44.8`
**Commit**: pymedusa/Medusa@f0cc6bc750b647546b99905b31df981ab45c0b0a
**Link to Log**: https://gist.github.com/599707074fcbdabbed4326ecc09548a7
### ERROR
<pre>
2017-08-30 03:01:53 ERROR    SHOWUPDATER :: [f0cc6bc] Problem running show_updater, Indexer TMDB seems to be having issues while trying to get updates for show Orange Is the New Black. Cause: 503 Server Error: Service Unavailable: Back-end server is at capacity for url: https://api.themoviedb.org/3/tv/changes?api_key=**********&start_date=2017-08-28&end_date=2017-09-11&page=3.
Traceback (most recent call last):
  File "/opt/medusa/medusa/show_updater.py", line 88, in run
    last_update, update_max_weeks
  File "/opt/medusa/medusa/indexers/tmdb/tmdb.py", line 523, in get_last_updated_series
    total_updates += self._get_all_updates(search_from.strftime('%Y-%m-%d'), search_until.strftime('%Y-%m-%d'))
  File "/opt/medusa/medusa/indexers/tmdb/tmdb.py", line 495, in _get_all_updates
    updates = self.tmdb.Changes().tv(start_date=start_date, end_date=end_date, page=page)
  File "/opt/medusa/lib/tmdbsimple/changes.py", line 79, in tv
    response = self._GET(path, kwargs)
  File "/opt/medusa/lib/tmdbsimple/base.py", line 87, in _GET
    return self._request('GET', path, params=params)
  File "/opt/medusa/lib/tmdbsimple/base.py", line 82, in _request
    response.raise_for_status()
  File "/opt/medusa/lib/requests/models.py", line 844, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
HTTPError: 503 Server Error: Service Unavailable: Back-end server is at capacity for url: https://api.themoviedb.org/3/tv/changes?api_key=**********&start_date=2017-08-28&end_date=2017-09-11&page=3
</pre>
---
_STAFF NOTIFIED_: @pymedusa/support @pymedusa/moderators


Discussion:

Resolving patch:
diff --git a/medusa/session/hooks.py b/medusa/session/hooks.py
--- a/medusa/session/hooks.py
+++ b/medusa/session/hooks.py
@@ -7,7 +7,6 @@
 import cfscrape
 
 from medusa.logger.adapters.style import BraceAdapter
-
 import requests
 from requests.utils import dict_from_cookiejar
 
diff --git a/medusa/show_updater.py b/medusa/show_updater.py
--- a/medusa/show_updater.py
+++ b/medusa/show_updater.py
@@ -21,6 +21,7 @@
 import time
 
 import app
+from requests.exceptions import HTTPError
 
 from . import db, network_timezones, ui
 from .helper.exceptions import CantRefreshShowException, CantUpdateShowException
@@ -97,6 +98,19 @@ def run(self, force=False):
                                        u'issues while trying to get updates for show {show}. Cause: {cause}',
                                        indexer_name=indexerApi(show.indexer).name, show=show.name, cause=e.message)
                         continue
+                    except HTTPError as error:
+                        if error.response.status_code == 503:
+                            logger.warning(u'Problem running show_updater, Indexer {indexer_name} seems to be having '
+                                           u'issues while trying to get updates for show {show}. '
+                                           u'Cause: TMDB api Service offline: '
+                                           u'This service is temporarily offline, try again later.',
+                                           indexer_name=indexerApi(show.indexer).name, show=show.name)
+                        if error.response.status_code == 429:
+                            logger.warning(u'Problem running show_updater, Indexer {indexer_name} seems to be having '
+                                           u'issues while trying to get updates for show {show}. '
+                                           u'Cause: Your request count (#) is over the allowed limit of (40)..',
+                                           indexer_name=indexerApi(show.indexer).name, show=show.name)
+                        continue
                     except Exception as e:
                         logger.exception(u'Problem running show_updater, Indexer {indexer_name} seems to be having '
                                          u'issues while trying to get updates for show {show}. Cause: {cause}.',


Test patch: