From 931d5f41c2914f845d9461631f8330bcd81f1219 Mon Sep 17 00:00:00 2001 From: echel0n Date: Fri, 12 Dec 2014 21:02:57 -0800 Subject: [PATCH] Fixed issue #1092 - auto post-processing scripts re-coded to work with new login system. --- autoProcessTV/autoProcessTV.py | 30 +++++++----------------------- 1 file changed, 7 insertions(+), 23 deletions(-) diff --git a/autoProcessTV/autoProcessTV.py b/autoProcessTV/autoProcessTV.py index e02ead47..28e893d0 100755 --- a/autoProcessTV/autoProcessTV.py +++ b/autoProcessTV/autoProcessTV.py @@ -22,6 +22,7 @@ from __future__ import with_statement import os.path import sys +import requests # Try importing Python 2 modules using new names try: @@ -35,20 +36,6 @@ except ImportError: import urllib.request as urllib2 from urllib.parse import urlencode -# workaround for broken urllib2 in python 2.6.5: wrong credentials lead to an infinite recursion -if sys.version_info >= (2, 6, 5) and sys.version_info < (2, 6, 6): - class HTTPBasicAuthHandler(urllib2.HTTPBasicAuthHandler): - def retry_http_basic_auth(self, host, req, realm): - # don't retry if auth failed - if req.get_header(self.auth_header, None) is not None: - return None - - return urllib2.HTTPBasicAuthHandler.retry_http_basic_auth(self, host, req, realm) - -else: - HTTPBasicAuthHandler = urllib2.HTTPBasicAuthHandler - - def processEpisode(dir_to_process, org_NZB_name=None, status=None): # Default values host = "localhost" @@ -125,20 +112,17 @@ def processEpisode(dir_to_process, org_NZB_name=None, status=None): else: protocol = "http://" - url = protocol + host + ":" + port + web_root + "home/postprocess/processEpisode?" + urlencode(params) + url = protocol + host + ":" + port + web_root + "home/postprocess/processEpisode" + login_url = protocol + host + ":" + port + web_root + "login" print ("Opening URL: " + url) try: - password_mgr = urllib2.HTTPPasswordMgrWithDefaultRealm() - password_mgr.add_password(None, url, username, password) - handler = HTTPBasicAuthHandler(password_mgr) - opener = urllib2.build_opener(handler) - urllib2.install_opener(opener) + sess = requests.Session() + sess.post(login_url, data={'username': username, 'password': password}, stream=True, verify=False) + result = sess.get(url, params=params, stream=True, verify=False) - result = opener.open(url).readlines() - - for line in result: + for line in result.iter_lines(): if line: print (line.strip())