From bcdc633a5e727c7396d56e00b67226e8b1b07620 Mon Sep 17 00:00:00 2001 From: Ruud Date: Sun, 21 Oct 2012 15:26:29 +0200 Subject: [PATCH] Use urlopen for Prowl notifier. fix #932 --- couchpotato/core/notifications/prowl/main.py | 34 ++++++++++++---------------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/couchpotato/core/notifications/prowl/main.py b/couchpotato/core/notifications/prowl/main.py index 715965d..0990d0d 100644 --- a/couchpotato/core/notifications/prowl/main.py +++ b/couchpotato/core/notifications/prowl/main.py @@ -1,39 +1,35 @@ -from couchpotato.core.helpers.encoding import toUnicode, tryUrlencode +from couchpotato.core.helpers.encoding import toUnicode from couchpotato.core.logger import CPLog from couchpotato.core.notifications.base import Notification -from httplib import HTTPSConnection +import traceback log = CPLog(__name__) class Prowl(Notification): + urls = { + 'api': 'https://api.prowlapp.com/publicapi/add' + } + def notify(self, message = '', data = {}, listener = None): if self.isDisabled(): return - http_handler = HTTPSConnection('api.prowlapp.com') - data = { 'apikey': self.conf('api_key'), 'application': self.default_title, 'description': toUnicode(message), 'priority': self.conf('priority'), } + headers = { + 'Content-type': 'application/x-www-form-urlencoded' + } - http_handler.request('POST', - '/publicapi/add', - headers = {'Content-type': 'application/x-www-form-urlencoded'}, - body = tryUrlencode(data) - ) - response = http_handler.getresponse() - request_status = response.status - - if request_status == 200: + try: + self.urlopen(self.urls['api'], headers = headers, params = data, multipart = True, show_error = False) log.info('Prowl notifications sent.') return True - elif request_status == 401: - log.error('Prowl auth failed: %s', response.reason) - return False - else: - log.error('Prowl notification failed.') - return False + except: + log.error('Prowl failed: %s', traceback.format_exc()) + + return False