Repository: Flexget/Flexget

Issue:
Notify (Pushbullet) Plugin Error.
Hi, since last week i have this error in my log. Up to this point everything worked without problems.
```
2019-11-13 10:30 ERROR    notify_entry  NexBox    'x-ratelimit-reset'
Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/flexget/components/notify/notify.py", line 104, in send_notification
    send_notification(*args, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/flexget/components/notify/notification_framework.py", line 124, in send_notification
    title, message, rendered_config
  File "/usr/local/lib/python3.5/dist-packages/flexget/components/notify/notifiers/pushbullet.py", line 89, in notify
    self.send_push(key, title, message, config.get('url'), d, 'device_iden')
  File "/usr/local/lib/python3.5/dist-packages/flexget/components/notify/notifiers/pushbullet.py", line 130, in send_push
    int(response.headers['X-Ratelimit-Reset'])
  File "/usr/local/lib/python3.5/dist-packages/requests/structures.py", line 52, in __getitem__
    return self._store[key.lower()][1]
KeyError: 'x-ratelimit-reset'
```
Flexget: 2.21.32
API: 1.5.0

Same with Flexget 3.0.8 and Python 3.8
Notify (Pushbullet) Plugin Error.
Hi, since last week i have this error in my log. Up to this point everything worked without problems.
```
2019-11-13 10:30 ERROR    notify_entry  NexBox    'x-ratelimit-reset'
Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/flexget/components/notify/notify.py", line 104, in send_notification
    send_notification(*args, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/flexget/components/notify/notification_framework.py", line 124, in send_notification
    title, message, rendered_config
  File "/usr/local/lib/python3.5/dist-packages/flexget/components/notify/notifiers/pushbullet.py", line 89, in notify
    self.send_push(key, title, message, config.get('url'), d, 'device_iden')
  File "/usr/local/lib/python3.5/dist-packages/flexget/components/notify/notifiers/pushbullet.py", line 130, in send_push
    int(response.headers['X-Ratelimit-Reset'])
  File "/usr/local/lib/python3.5/dist-packages/requests/structures.py", line 52, in __getitem__
    return self._store[key.lower()][1]
KeyError: 'x-ratelimit-reset'
```
Flexget: 2.21.32
API: 1.5.0

Same with Flexget 3.0.8 and Python 3.8


Discussion:
Having the same problem. The push message goes trough, but these errors show up in the log.
From a simple test manually sending the message, I did not get the `X-Ratelimit-` fields on the response header of a regular push. Could they be sending those only when reaching the rate limit?

If that's the case (can't test it while not rate limited) omitting the following debug message should be enough.
https://github.com/Flexget/Flexget/blob/00bba32cd38127f82e6ceb67ce73d147c1f37652/flexget/components/notify/notifiers/pushbullet.py#L128-L137
> 
> 
> Having the same problem. The push message goes trough, but these errors show up in the log.
> From a simple test manually sending the message, I did not get the `X-Ratelimit-` fields on the response header of a regular push. Could they be sending those only when reaching the rate limit?
> 
> If that's the case (can't test it while not rate limited) omitting the following debug message should be enough.
> 
> https://github.com/Flexget/Flexget/blob/00bba32cd38127f82e6ceb67ce73d147c1f37652/flexget/components/notify/notifiers/pushbullet.py#L128-L137

No, it does not help.
```
2019-11-27 01:12 ERROR    notify_entry  Rutor_BDRip _1080p 'x-ratelimit-reset'
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/flexget/components/notify/notify.py", line 101, in send_notification
    send_notification(*args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/flexget/components/notify/notification_framework.py", line 121, in send_notification
    notifier_plugin.notify(
  File "/usr/local/lib/python3.8/site-packages/flexget/components/notify/notifiers/pushbullet.py", line 88, in notify
    self.send_push(key, title, message, config.get('url'), d, 'device_iden')
  File "/usr/local/lib/python3.8/site-packages/flexget/components/notify/notifiers/pushbullet.py", line 129, in send_push
    #            int(response.headers['X-Ratelimit-Reset'])
  File "/usr/local/lib/python3.8/site-packages/requests/structures.py", line 52, in __getitem__
    return self._store[key.lower()][1]
KeyError: 'x-ratelimit-reset'
```
Having the same problem. The push message goes trough, but these errors show up in the log.
From a simple test manually sending the message, I did not get the `X-Ratelimit-` fields on the response header of a regular push. Could they be sending those only when reaching the rate limit?

If that's the case (can't test it while not rate limited) omitting the following debug message should be enough.
https://github.com/Flexget/Flexget/blob/00bba32cd38127f82e6ceb67ce73d147c1f37652/flexget/components/notify/notifiers/pushbullet.py#L128-L137
> 
> 
> Having the same problem. The push message goes trough, but these errors show up in the log.
> From a simple test manually sending the message, I did not get the `X-Ratelimit-` fields on the response header of a regular push. Could they be sending those only when reaching the rate limit?
> 
> If that's the case (can't test it while not rate limited) omitting the following debug message should be enough.
> 
> https://github.com/Flexget/Flexget/blob/00bba32cd38127f82e6ceb67ce73d147c1f37652/flexget/components/notify/notifiers/pushbullet.py#L128-L137

No, it does not help.
```
2019-11-27 01:12 ERROR    notify_entry  Rutor_BDRip _1080p 'x-ratelimit-reset'
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/flexget/components/notify/notify.py", line 101, in send_notification
    send_notification(*args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/flexget/components/notify/notification_framework.py", line 121, in send_notification
    notifier_plugin.notify(
  File "/usr/local/lib/python3.8/site-packages/flexget/components/notify/notifiers/pushbullet.py", line 88, in notify
    self.send_push(key, title, message, config.get('url'), d, 'device_iden')
  File "/usr/local/lib/python3.8/site-packages/flexget/components/notify/notifiers/pushbullet.py", line 129, in send_push
    #            int(response.headers['X-Ratelimit-Reset'])
  File "/usr/local/lib/python3.8/site-packages/requests/structures.py", line 52, in __getitem__
    return self._store[key.lower()][1]
KeyError: 'x-ratelimit-reset'
```

Resolving patch:
diff --git a/flexget/components/notify/notifiers/pushover.py b/flexget/components/notify/notifiers/pushover.py
--- a/flexget/components/notify/notifiers/pushover.py
+++ b/flexget/components/notify/notifiers/pushover.py
@@ -111,12 +111,15 @@ def notify(self, title, message, config):
             except RequestException as e:
                 if e.response is not None:
                     if e.response.status_code == 429:
-                        reset_time = datetime.datetime.fromtimestamp(
-                            int(e.response.headers['X-Limit-App-Reset'])
-                        ).strftime('%Y-%m-%d %H:%M:%S')
-                        error_message = (
-                            'Monthly pushover message limit reached. Next reset: %s' % reset_time
-                        )
+                        app_reset = e.response.headers.get('X-Limit-App-Reset')
+                        if app_reset:
+                            reset_time = datetime.datetime.fromtimestamp(int(app_reset)).strftime(
+                                '%Y-%m-%d %H:%M:%S'
+                            )
+                            error_message = (
+                                f'Monthly pushover message limit reached. Next reset: {reset_time}'
+                            )
+
                     else:
                         error_message = e.response.json()['errors'][0]
                 else:


Test patch: