diff --git a/apprise/plugins/NotifySlack.py b/apprise/plugins/NotifySlack.py index 6a05bcbd..b17ecd85 100644 --- a/apprise/plugins/NotifySlack.py +++ b/apprise/plugins/NotifySlack.py @@ -525,25 +525,29 @@ class NotifySlack(NotifyBase): 'Response Details:\r\n{}'.format(r.content)) return False - try: - response = loads(r.content) + elif attach: + # Attachment posts return a JSON string + try: + response = loads(r.content) - except (AttributeError, TypeError, ValueError): - # ValueError = r.content is Unparsable - # TypeError = r.content is None - # AttributeError = r is None - pass + except (AttributeError, TypeError, ValueError): + # ValueError = r.content is Unparsable + # TypeError = r.content is None + # AttributeError = r is None + pass - if not (response and response.get('ok', True)): - # Bare minimum requirements not met - self.logger.warning( - 'Failed to send {}to Slack: error={}.'.format( - attach.name if attach else '', - r.status_code)) + if not (response and response.get('ok', True)): + # Bare minimum requirements not met + self.logger.warning( + 'Failed to send {}to Slack: error={}.'.format( + attach.name if attach else '', + r.status_code)) - self.logger.debug( - 'Response Details:\r\n{}'.format(r.content)) - return False + self.logger.debug( + 'Response Details:\r\n{}'.format(r.content)) + return False + else: + response = r.content # Message Post Response looks like this: # { diff --git a/test/test_slack_plugin.py b/test/test_slack_plugin.py index 9ee6b67e..2613bff8 100644 --- a/test/test_slack_plugin.py +++ b/test/test_slack_plugin.py @@ -116,7 +116,7 @@ def test_slack_oauth_access_token(mock_post): request.content = '{' # As a result, we'll fail to send our notification - assert obj.send(body="test") is False + assert obj.send(body="test", attach=attach) is False request.content = dumps({ 'ok': False, @@ -125,7 +125,7 @@ def test_slack_oauth_access_token(mock_post): # A response from Slack (even with a 200 response) still # results in a failure: - assert obj.send(body="test") is False + assert obj.send(body="test", attach=attach) is False # Handle exceptions reading our attachment from disk (should it happen) mock_post.side_effect = OSError("Attachment Error")