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'
```
Accidentally "fixed" the wrong plugin 🤣 
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'
```
Accidentally "fixed" the wrong plugin 🤣 

Resolving patch:
diff --git a/flexget/components/notify/notifiers/pushbullet.py b/flexget/components/notify/notifiers/pushbullet.py
--- a/flexget/components/notify/notifiers/pushbullet.py
+++ b/flexget/components/notify/notifiers/pushbullet.py
@@ -112,13 +112,12 @@ def send_push(self, api_key, title, body, url=None, destination=None, destinatio
         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-Ratelimit-Reset'])
-                    ).strftime('%Y-%m-%d %H:%M:%S')
-                    message = (
-                        'Monthly Pushbullet database operations limit reached. Next reset: %s'
-                        % reset_time
-                    )
+                    reset_time = e.response.headers.get('X-Ratelimit-Reset')
+                    if reset_time:
+                        reset_time = datetime.datetime.fromtimestamp(int(reset_time)).strftime(
+                            '%Y-%m-%d %H:%M:%S'
+                        )
+                        message = f'Monthly Pushbullet database operations limit reached. Next reset: {reset_time}'
                 else:
                     message = e.response.json()['error']['message']
             else:


Test patch: