Use urlopen for Prowl notifier. fix #932
This commit is contained in:
1 parent
19f74e398f
commit
bcdc633a5e
1 file changed
+15
-19
@@ -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.logger import CPLog
|
||||||
from couchpotato.core.notifications.base import Notification
|
from couchpotato.core.notifications.base import Notification
|
||||||
from httplib import HTTPSConnection
|
import traceback
|
||||||
|
|
||||||
log = CPLog(__name__)
|
log = CPLog(__name__)
|
||||||
|
|
||||||
|
|
||||||
class Prowl(Notification):
|
class Prowl(Notification):
|
||||||
|
|
||||||
|
urls = {
|
||||||
|
'api': 'https://api.prowlapp.com/publicapi/add'
|
||||||
|
}
|
||||||
|
|
||||||
def notify(self, message = '', data = {}, listener = None):
|
def notify(self, message = '', data = {}, listener = None):
|
||||||
if self.isDisabled(): return
|
if self.isDisabled(): return
|
||||||
|
|
||||||
http_handler = HTTPSConnection('api.prowlapp.com')
|
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
'apikey': self.conf('api_key'),
|
'apikey': self.conf('api_key'),
|
||||||
'application': self.default_title,
|
'application': self.default_title,
|
||||||
'description': toUnicode(message),
|
'description': toUnicode(message),
|
||||||
'priority': self.conf('priority'),
|
'priority': self.conf('priority'),
|
||||||
}
|
}
|
||||||
|
headers = {
|
||||||
|
'Content-type': 'application/x-www-form-urlencoded'
|
||||||
|
}
|
||||||
|
|
||||||
http_handler.request('POST',
|
try:
|
||||||
'/publicapi/add',
|
self.urlopen(self.urls['api'], headers = headers, params = data, multipart = True, show_error = False)
|
||||||
headers = {'Content-type': 'application/x-www-form-urlencoded'},
|
|
||||||
body = tryUrlencode(data)
|
|
||||||
)
|
|
||||||
response = http_handler.getresponse()
|
|
||||||
request_status = response.status
|
|
||||||
|
|
||||||
if request_status == 200:
|
|
||||||
log.info('Prowl notifications sent.')
|
log.info('Prowl notifications sent.')
|
||||||
return True
|
return True
|
||||||
elif request_status == 401:
|
except:
|
||||||
log.error('Prowl auth failed: %s', response.reason)
|
log.error('Prowl failed: %s', traceback.format_exc())
|
||||||
return False
|
|
||||||
else:
|
return False
|
||||||
log.error('Prowl notification failed.')
|
|
||||||
return False
|
|
||||||
Reference in new issue
Block a user