Repository: pymedusa/Medusa

Issue:
[APP SUBMITTED]: KeyError: 362496

### INFO
**Python Version**: `2.7.14 (default, May 28 2018, 14:47:18) [GCC 4.7.3 20130102 (prerelease)]`
**Operating System**: `Linux-3.10.105-x86_64-with-glibc2.2.5`
**Locale**: `None`
**Branch**: [develop](../tree/develop)
**Database**: `44.14`
**Commit**: pymedusa/Medusa@ae5acb0e7a025200c2cb671907b2255905ce480d
**Link to Log**: https://gist.github.com/5ee25b93e879594f85845a6f8adf2f35
### ERROR
<pre>
2019-12-19 02:00:48 ERROR    SHOWUPDATER :: [ae5acb0] Problem running show_updater, Indexer TVDBv2 seems to be having issues while trying to get updates for show Marvel's Falcon & Winter Soldier. Cause: KeyError(362496,)
Traceback (most recent call last):
  File "/volume1/@appstore/sickbeard-custom/var/SickBeard/<a href="../blob/ae5acb0e7a025200c2cb671907b2255905ce480d/medusa/show_updater.py#L147">medusa/show_updater.py</a>", line 147, in run
    update_max_weeks)
  File "/volume1/@appstore/sickbeard-custom/var/SickBeard/<a href="../blob/ae5acb0e7a025200c2cb671907b2255905ce480d/medusa/indexers/tvdbv2/tvdbv2_api.py#L666">medusa/indexers/tvdbv2/tvdbv2_api.py</a>", line 666, in get_last_updated_seasons
    episodes = self._query_series(show_id)
  File "/volume1/@appstore/sickbeard-custom/var/SickBeard/<a href="../blob/ae5acb0e7a025200c2cb671907b2255905ce480d/medusa/indexers/tvdbv2/fallback.py#L135">medusa/indexers/tvdbv2/fallback.py</a>", line 135, in __call__
    return self.func(*args, **kwargs)
  File "/volume1/@appstore/sickbeard-custom/var/SickBeard/<a href="../blob/ae5acb0e7a025200c2cb671907b2255905ce480d/medusa/indexers/tvdbv2/tvdbv2_api.py#L294">medusa/indexers/tvdbv2/tvdbv2_api.py</a>", line 294, in _query_series
    if error.status == 404 and not self.shows[tvdb_id]['firstaired']:
KeyError: 362496
</pre>
---
_STAFF NOTIFIED_: @pymedusa/support @pymedusa/moderators



Discussion:

### INFO
**Python Version**: `3.8.1 (default, Dec 30 2019, 15:43:37) [GCC 9.2.0]`
**Operating System**: `Linux-3.10.105-x86_64-with`
**Locale**: `UTF-8`
**Branch**: [master](../tree/master)
**Database**: `44.14`
**Commit**: pymedusa/Medusa@
**Link to Log**: https://gist.github.com/2a49a6206ec366830c3b8578950e27e4
### ERROR
<pre>
2020-01-05 04:00:47 ERROR    SHOWUPDATER :: [] Problem running show_updater, Indexer TVDBv2 seems to be having issues while trying to get updates for show Marvel's Falcon & Winter Soldier. Cause: KeyError(362496)
Traceback (most recent call last):
  File "/app/medusa/ext/tvdbapiv2/rest.py", line 54, in request
    r.raise_for_status()
  File "/app/medusa/ext/requests/models.py", line 940, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 404 Client Error: Not Found for url: https://tvdb2.plex.tv/series/362496/episodes/query?page=1

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/app/medusa/medusa/indexers/tvdbv2/tvdbv2_api.py", line 276, in _query_series
    paged_episodes = self.config['session'].series_api.series_id_episodes_query_get(
  File "/app/medusa/ext/tvdbapiv2/apis/series_api.py", line 459, in series_id_episodes_query_get
    response = self.api_client.call_api(resource_path, method,
  File "/app/medusa/ext/tvdbapiv2/api_client.py", line 292, in call_api
    return self.__call_api(resource_path, method,
  File "/app/medusa/ext/tvdbapiv2/api_client.py", line 119, in __call_api
    response_data = self.request(method, url,
  File "/app/medusa/ext/tvdbapiv2/api_client.py", line 313, in request
    return self.rest_client.get(url,
  File "/app/medusa/ext/tvdbapiv2/rest.py", line 68, in get
    return self.request("GET", url,
  File "/app/medusa/ext/tvdbapiv2/rest.py", line 63, in request
    raise ApiException(status=status, reason=msg)
tvdbapiv2.exceptions.ApiException: (404)
Reason: HTTPError
404 Client Error: Not Found for url: https://tvdb2.plex.tv/series/362496/episodes/query?page=1


During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/app/medusa/medusa/show_updater.py", line 146, in run
    updated_seasons = indexer_api.get_last_updated_seasons([show.indexerid], last_update,
  File "/app/medusa/medusa/indexers/tvdbv2/tvdbv2_api.py", line 666, in get_last_updated_seasons
    episodes = self._query_series(show_id)
  File "/app/medusa/medusa/indexers/tvdbv2/fallback.py", line 135, in __call__
    return self.func(*args, **kwargs)
  File "/app/medusa/medusa/indexers/tvdbv2/tvdbv2_api.py", line 294, in _query_series
    if error.status == 404 and not self.shows[tvdb_id]['firstaired']:
KeyError: 362496
</pre>
---
_STAFF NOTIFIED_: @pymedusa/support @pymedusa/moderators


### INFO
**Python Version**: `2.7.13 (v2.7.13:a06454b1afa1, Dec 17 2016, 20:53:40) [MSC v.1500 64 bit (AMD64)]`
**Operating System**: `Windows-10-10.0.18362`
**Locale**: `cp1252`
**Branch**: [master](../tree/master)
**Database**: `44.14`
**Commit**: pymedusa/Medusa@d0c136d7a528a471b51676140bd35d24d97f65c6
**Link to Log**: https://gist.github.com/f902fd0f150fe46b47da71d85504ad26
### ERROR
<pre>
2020-01-13 04:00:29 ERROR    SHOWUPDATER :: [d0c136d] Problem running show_updater, Indexer TVDBv2 seems to be having issues while trying to get updates for show Marvel's Falcon & Winter Soldier. Cause: KeyError(362496,)
Traceback (most recent call last):
  File "C:\Data\Medusa\Medusa\<a href="../blob/d0c136d7a528a471b51676140bd35d24d97f65c6/medusa/show_updater.py#L147">medusa\show_updater.py</a>", line 147, in run
    update_max_weeks)
  File "C:\Data\Medusa\Medusa\<a href="../blob/d0c136d7a528a471b51676140bd35d24d97f65c6/medusa/indexers/tvdbv2/tvdbv2_api.py#L666">medusa\indexers\tvdbv2\tvdbv2_api.py</a>", line 666, in get_last_updated_seasons
    episodes = self._query_series(show_id)
  File "C:\Data\Medusa\Medusa\<a href="../blob/d0c136d7a528a471b51676140bd35d24d97f65c6/medusa/indexers/tvdbv2/fallback.py#L135">medusa\indexers\tvdbv2\fallback.py</a>", line 135, in __call__
    return self.func(*args, **kwargs)
  File "C:\Data\Medusa\Medusa\<a href="../blob/d0c136d7a528a471b51676140bd35d24d97f65c6/medusa/indexers/tvdbv2/tvdbv2_api.py#L294">medusa\indexers\tvdbv2\tvdbv2_api.py</a>", line 294, in _query_series
    if error.status == 404 and not self.shows[tvdb_id]['firstaired']:
KeyError: 362496
</pre>
---
_STAFF NOTIFIED_: @pymedusa/support @pymedusa/moderators


### INFO
**Python Version**: `2.7.14 (default, May 28 2018, 14:47:18) [GCC 4.7.3 20130102 (prerelease)]`
**Operating System**: `Linux-4.4.59+-x86_64-with-glibc2.2.5`
**Locale**: `None`
**Branch**: [master](../tree/master)
**Database**: `44.14`
**Commit**: pymedusa/Medusa@9a364616d1bc7bed025f3c08270ac993cfa0c046
**Link to Log**: https://gist.github.com/62e3d78312f3727a40feb4a08f2513e1
### ERROR
<pre>
2020-02-05 02:00:49 ERROR    SHOWUPDATER :: [9a36461] Problem running show_updater, Indexer TVDBv2 seems to be having issues while trying to get updates for show Marvel's Falcon & Winter Soldier. Cause: KeyError(362496,)
Traceback (most recent call last):
  File "/volume1/@appstore/medusa/var/SickBeard/<a href="../blob/9a364616d1bc7bed025f3c08270ac993cfa0c046/medusa/show_updater.py#L147">medusa/show_updater.py</a>", line 147, in run
    update_max_weeks)
  File "/volume1/@appstore/medusa/var/SickBeard/<a href="../blob/9a364616d1bc7bed025f3c08270ac993cfa0c046/medusa/indexers/tvdbv2/tvdbv2_api.py#L666">medusa/indexers/tvdbv2/tvdbv2_api.py</a>", line 666, in get_last_updated_seasons
    episodes = self._query_series(show_id)
  File "/volume1/@appstore/medusa/var/SickBeard/<a href="../blob/9a364616d1bc7bed025f3c08270ac993cfa0c046/medusa/indexers/tvdbv2/fallback.py#L135">medusa/indexers/tvdbv2/fallback.py</a>", line 135, in __call__
    return self.func(*args, **kwargs)
  File "/volume1/@appstore/medusa/var/SickBeard/<a href="../blob/9a364616d1bc7bed025f3c08270ac993cfa0c046/medusa/indexers/tvdbv2/tvdbv2_api.py#L294">medusa/indexers/tvdbv2/tvdbv2_api.py</a>", line 294, in _query_series
    if error.status == 404 and not self.shows[tvdb_id]['firstaired']:
KeyError: 362496
</pre>
---
_STAFF NOTIFIED_: @pymedusa/support @pymedusa/moderators


Resolving patch:
diff --git a/medusa/indexers/tvdbv2/tvdbv2_api.py b/medusa/indexers/tvdbv2/tvdbv2_api.py
--- a/medusa/indexers/tvdbv2/tvdbv2_api.py
+++ b/medusa/indexers/tvdbv2/tvdbv2_api.py
@@ -289,9 +289,12 @@ def _query_series(self, tvdb_id, specials=False, aired_season=None, full_info=Fa
                     .format(reason=error.reason, status=error.status)
                 )
 
-            if error.status == 404 and not self.shows[tvdb_id]['firstaired']:
-                log.info('Show {name} does not have any episodes yet, adding it anyway',
-                         {'name': self.shows[tvdb_id]['seriesname']})
+            if error.status == 404:
+                show_data = self.shows.get(tvdb_id)
+                if show_data and not show_data['firstaired']:
+                    log.info('Show {name} does not have any episodes yet.',
+                             {'name': self.shows[tvdb_id]['seriesname']})
+
             else:
                 raise IndexerUnavailable(
                     'Error connecting to TVDB API. Reason: {reason}'.format(


Test patch: