Fix KeyError

This commit is contained in:
Fabian Affolter 2017-07-17 20:21:16 +02:00
parent c67c20f752
commit 95e0027924
No known key found for this signature in database
GPG Key ID: DDF3D6F44AAB1336

View File

@ -65,7 +65,7 @@ class TwitterNotificationService(BaseNotificationService):
if data:
media = data.get(ATTR_MEDIA)
if not self.hass.config.is_allowed_path(media):
_LOGGER.warning("'%s' is not in a whitelisted area.", media)
_LOGGER.warning("'%s' is not a whitelisted directory", media)
return
media_id = self.upload_media(media)
@ -97,8 +97,7 @@ class TwitterNotificationService(BaseNotificationService):
return None
media_id = resp.json()['media_id']
media_id = self.upload_media_chunked(file, total_bytes,
media_id)
media_id = self.upload_media_chunked(file, total_bytes, media_id)
resp = self.upload_media_finalize(media_id)
if 199 > resp.status_code < 300:
@ -150,8 +149,8 @@ class TwitterNotificationService(BaseNotificationService):
def log_error_resp(resp):
"""Log error response."""
obj = json.loads(resp.text)
error_message = obj['error']
_LOGGER.error("Error %s : %s", resp.status_code, error_message)
error_message = obj['errors']
_LOGGER.error("Error %s: %s", resp.status_code, error_message)
@staticmethod
def log_error_resp_append(resp):
@ -159,5 +158,5 @@ class TwitterNotificationService(BaseNotificationService):
obj = json.loads(resp.text)
error_message = obj['errors'][0]['message']
error_code = obj['errors'][0]['code']
_LOGGER.error("Error %s : %s (Code %s)", resp.status_code,
_LOGGER.error("Error %s: %s (Code %s)", resp.status_code,
error_message, error_code)