From 645c2ecef61226b81c5271f7e44105c9aae3d6e1 Mon Sep 17 00:00:00 2001 From: JonnyWong16 Date: Mon, 3 Feb 2020 18:11:56 -0800 Subject: [PATCH] Use Authorization header for GitHub API --- plexpy/versioncheck.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/plexpy/versioncheck.py b/plexpy/versioncheck.py index b9440c19..dce083aa 100644 --- a/plexpy/versioncheck.py +++ b/plexpy/versioncheck.py @@ -158,13 +158,17 @@ def check_update(auto_update=False, notify=False): def check_github(auto_update=False, notify=False): plexpy.COMMITS_BEHIND = 0 + if plexpy.CONFIG.GIT_TOKEN: + headers = {'Authorization': 'token {}'.format(plexpy.CONFIG.GIT_TOKEN)} + else: + headers = {} + # Get the latest version available from github logger.info('Retrieving latest version information from GitHub') url = 'https://api.github.com/repos/%s/%s/commits/%s' % (plexpy.CONFIG.GIT_USER, plexpy.CONFIG.GIT_REPO, plexpy.CONFIG.GIT_BRANCH) - if plexpy.CONFIG.GIT_TOKEN: url = url + '?access_token=%s' % plexpy.CONFIG.GIT_TOKEN - version = request.request_json(url, timeout=20, validator=lambda x: type(x) == dict) + version = request.request_json(url, headers=headers, timeout=20, validator=lambda x: type(x) == dict) if version is None: logger.warn('Could not get the latest version from GitHub. Are you running a local development version?') @@ -187,8 +191,8 @@ def check_github(auto_update=False, notify=False): plexpy.CONFIG.GIT_REPO, plexpy.LATEST_VERSION, plexpy.CURRENT_VERSION) - if plexpy.CONFIG.GIT_TOKEN: url = url + '?access_token=%s' % plexpy.CONFIG.GIT_TOKEN - commits = request.request_json(url, timeout=20, whitelist_status_code=404, validator=lambda x: type(x) == dict) + commits = request.request_json(url, headers=headers, timeout=20, whitelist_status_code=404, + validator=lambda x: type(x) == dict) if commits is None: logger.warn('Could not get commits behind from GitHub.')