Skip to content

Instantly share code, notes, and snippets.

@badboybeyer
Created November 25, 2019 20:25
Show Gist options
  • Save badboybeyer/839bee6b5eb58f9a3abe48cdfe4e0150 to your computer and use it in GitHub Desktop.
Save badboybeyer/839bee6b5eb58f9a3abe48cdfe4e0150 to your computer and use it in GitHub Desktop.
tvdb api patch for sickgear
diff --git a/lib/tvdb_api/tvdb_api.py b/lib/tvdb_api/tvdb_api.py
index 1cd1a839..2e68e324 100644
--- a/lib/tvdb_api/tvdb_api.py
+++ b/lib/tvdb_api/tvdb_api.py
@@ -18,6 +18,7 @@ import tempfile
import warnings
import logging
import requests
+from requests.auth import AuthBase
import requests.exceptions
import datetime
import re
@@ -581,7 +582,7 @@ class Tvdb:
log().debug('Using proxy for URL: %s' % url)
session.proxies = {'http': self.config['proxy'], 'https': self.config['proxy']}
- headers = {'Accept-Encoding': 'gzip,deflate', 'Authorization': 'Bearer %s' % self.get_token(),
+ headers = {'Accept-Encoding': 'gzip,deflate',
'Accept': 'application/vnd.thetvdb.v%s' % __api_version__}
if None is not language and language in self.config['valid_languages']:
@@ -594,7 +595,8 @@ class Tvdb:
self.not_found = False
try:
resp = getURL(url.strip(), params=params, session=session, headers=headers, json=True,
- raise_status_code=True, raise_exceptions=True)
+ raise_status_code=True, raise_exceptions=True,
+ auth=TVDBAuth(self.get_token()))
except requests.exceptions.HTTPError as e:
if 401 == e.response.status_code:
# token expired, get new token, raise error to retry
@@ -1097,5 +1099,17 @@ def main():
print tvdb_instance['Lost'][1][4]['episodename']
+class TVDBAuth(AuthBase):
+ """Attaches TVDB Authentication to the given Request object."""
+ def __init__(self, token):
+ # setup any auth-related data here
+ self.token = token
+
+ def __call__(self, r):
+ # modify and return the request
+ r.headers['Authorization'] = 'Bearer %s' % self.token
+ return r
+
+
if '__main__' == __name__:
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment