diff --git a/CHANGELOG.md b/CHANGELOG.md index a3b702ad..08c067f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ Released xx xxx 2015 Highlights: *Improved: Specify whether to delete folders when force post-processing *Improved: Convert target bitrate to vbr preset for what.cd searching +*Improved: Switched Pushover to requests lib The full list of commits can be found [here](https://github.com/rembo10/headphones/compare/v0.5.6...v0.5.7). diff --git a/headphones/notifiers.py b/headphones/notifiers.py index 5592a347..24d83b91 100644 --- a/headphones/notifiers.py +++ b/headphones/notifiers.py @@ -583,7 +583,7 @@ class PUSHOVER(object): if not headphones.CONFIG.PUSHOVER_ENABLED: return - http_handler = HTTPSConnection("api.pushover.net") + url = "https://api.pushover.net/1/messages.json" data = {'token': self.application_token, 'user': headphones.CONFIG.PUSHOVER_KEYS, @@ -591,25 +591,16 @@ class PUSHOVER(object): 'message': message.encode("utf-8"), 'priority': headphones.CONFIG.PUSHOVER_PRIORITY} - http_handler.request("POST", - "/1/messages.json", - headers={'Content-type': "application/x-www-form-urlencoded"}, - body=urlencode(data)) - response = http_handler.getresponse() - request_status = response.status - logger.debug(u"Pushover response status: %r" % request_status) - logger.debug(u"Pushover response headers: %r" % response.getheaders()) - logger.debug(u"Pushover response body: %r" % response.read()) + headers = {'Content-type': "application/x-www-form-urlencoded"} - if request_status == 200: - logger.info(u"Pushover notifications sent.") - return True - elif request_status >= 400 and request_status < 500: - logger.info(u"Pushover request failed: %s" % response.reason) - return False + response = request.request_response(url, method="POST", headers=headers, data=data) + + if response: + logger.info(u"Pushover notifications sent.") + return True else: - logger.info(u"Pushover notification failed.") - return False + logger.error(u"Pushover notification failed.") + return False def updateLibrary(self): #For uniformity reasons not removed diff --git a/headphones/webserve.py b/headphones/webserve.py index 706e0018..280d1376 100644 --- a/headphones/webserve.py +++ b/headphones/webserve.py @@ -1430,7 +1430,7 @@ class WebInterface(object): logger.info(u"Sending Pushover notification") pushover = notifiers.PUSHOVER() result = pushover.notify("hooray!", "This is a test") - return result + return str(result) class Artwork(object): @cherrypy.expose