From 6db2836662fcbb31a9c47a8f3052870d9a87e5a3 Mon Sep 17 00:00:00 2001 From: rembo10 Date: Tue, 7 Jul 2015 22:54:34 -0700 Subject: [PATCH] Moved plex notifications to requests lib for pre-v12 plex --- headphones/notifiers.py | 26 +++++--------------------- 1 file changed, 5 insertions(+), 21 deletions(-) diff --git a/headphones/notifiers.py b/headphones/notifiers.py index a383d2e5..b3afa0ca 100644 --- a/headphones/notifiers.py +++ b/headphones/notifiers.py @@ -320,28 +320,12 @@ class Plex(object): def _sendhttp(self, host, command): - username = self.username - password = self.password + url = host + '/xbmcCmds/xbmcHttp/?' + command - url_command = urllib.urlencode(command) - - url = host + '/xbmcCmds/xbmcHttp/?' + url_command - - req = urllib2.Request(url) - - if password: - base64string = base64.encodestring('%s:%s' % (username, password)).replace('\n', '') - req.add_header("Authorization", "Basic %s" % base64string) - - logger.info('Plex url: %s' % url) - - try: - handle = urllib2.urlopen(req) - except Exception as e: - logger.warn('Error opening Plex url: %s' % e) - return - - response = handle.read().decode(headphones.SYS_ENCODING) + if self.password: + response = request.request_response(url, auth=(self.username, self.password)) + else: + response = request.request_response(url) return response