From a233db002473af894e03b87edc4d09e81a5fbf7e Mon Sep 17 00:00:00 2001 From: Clinton Hall Date: Mon, 2 Mar 2020 18:19:57 +1300 Subject: [PATCH] SickGear 403 fix (#1722) 403 from SickGear #1704 --- core/auto_process/tv.py | 4 ++-- core/forks.py | 11 +++++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/core/auto_process/tv.py b/core/auto_process/tv.py index 801f3234..6b3ba7b7 100644 --- a/core/auto_process/tv.py +++ b/core/auto_process/tv.py @@ -272,7 +272,7 @@ def process(section, dir_name, input_name=None, failed=False, client_agent='manu url = None if section == 'SickBeard': if apikey: - url = '{0}{1}:{2}{3}/api/{4}/?cmd=postprocess'.format(protocol, host, port, web_root, apikey) + url = '{0}{1}:{2}{3}/api/{4}/'.format(protocol, host, port, web_root, apikey) elif fork == 'Stheno': url = '{0}{1}:{2}{3}/home/postprocess/process_episode'.format(protocol, host, port, web_root) else: @@ -300,7 +300,7 @@ def process(section, dir_name, input_name=None, failed=False, client_agent='manu login = '{0}{1}:{2}{3}/login'.format(protocol, host, port, web_root) login_params = {'username': username, 'password': password} r = s.get(login, verify=False, timeout=(30, 60)) - if r.status_code == 401 and r.cookies.get('_xsrf'): + if r.status_code in [401, 403] and r.cookies.get('_xsrf'): login_params['_xsrf'] = r.cookies.get('_xsrf') s.post(login, data=login_params, stream=True, verify=False, timeout=(30, 60)) r = s.get(url, auth=(username, password), params=fork_params, stream=True, verify=False, timeout=(30, 1800)) diff --git a/core/forks.py b/core/forks.py index ac73c547..19efad0e 100644 --- a/core/forks.py +++ b/core/forks.py @@ -104,7 +104,7 @@ def auto_fork(section, input_category): # then in order of most unique parameters. if apikey: - url = '{protocol}{host}:{port}{root}/api/{apikey}/?cmd=help&subject=postprocess'.format( + url = '{protocol}{host}:{port}{root}/api/{apikey}/?cmd=sg.postprocess&help=1'.format( protocol=protocol, host=host, port=port, root=web_root, apikey=apikey, ) else: @@ -120,7 +120,7 @@ def auto_fork(section, input_category): protocol=protocol, host=host, port=port, root=web_root) login_params = {'username': username, 'password': password} r = s.get(login, verify=False, timeout=(30, 60)) - if r.status_code == 401 and r.cookies.get('_xsrf'): + if r.status_code in [401, 403] and r.cookies.get('_xsrf'): login_params['_xsrf'] = r.cookies.get('_xsrf') s.post(login, data=login_params, stream=True, verify=False) r = s.get(url, auth=(username, password), verify=False) @@ -131,8 +131,10 @@ def auto_fork(section, input_category): if r and r.ok: if apikey: rem_params, found = api_check(r, params, rem_params) - if not found: # try different api set for SickGear. - url = '{protocol}{host}:{port}{root}/api/{apikey}/?cmd=postprocess&help=1'.format( + if found: + params['cmd'] = 'sg.postprocess' + else: # try different api set for non-SickGear forks. + url = '{protocol}{host}:{port}{root}/api/{apikey}/?cmd=help&subject=postprocess'.format( protocol=protocol, host=host, port=port, root=web_root, apikey=apikey, ) try: @@ -141,6 +143,7 @@ def auto_fork(section, input_category): logger.info('Could not connect to {section}:{category} to perform auto-fork detection!'.format (section=section, category=input_category)) rem_params, found = api_check(r, params, rem_params) + params['cmd'] = 'postprocess' else: # Find excess parameters rem_params.extend(