From a09e0cbeaa06152351ff38e910440a71bca8fe06 Mon Sep 17 00:00:00 2001 From: Roman Davydov <15850461+rdavydov@users.noreply.github.com> Date: Sun, 6 Oct 2024 13:00:48 +0300 Subject: [PATCH] fix Error: KeyError: 'data' rdavydov/Twitch-Channel-Points-Miner-v2#593 --- TwitchChannelPointsMiner/classes/Twitch.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/TwitchChannelPointsMiner/classes/Twitch.py b/TwitchChannelPointsMiner/classes/Twitch.py index ea12537a..30c30544 100644 --- a/TwitchChannelPointsMiner/classes/Twitch.py +++ b/TwitchChannelPointsMiner/classes/Twitch.py @@ -19,6 +19,7 @@ # from urllib.parse import quote # from base64 import urlsafe_b64decode # from datetime import datetime +from typing import Dict, Any from TwitchChannelPointsMiner.classes.entities.Campaign import Campaign from TwitchChannelPointsMiner.classes.entities.Drop import Drop @@ -46,6 +47,7 @@ ) logger = logging.getLogger(__name__) +JsonType = Dict[str, Any] class Twitch(object): @@ -492,9 +494,14 @@ def send_minute_watched_events(self, streamers, priority, chunk_size=3): logger.debug( f"Sent PlaybackAccessToken request for {streamers[index]}" ) - signature = responsePlaybackAccessToken["data"]['streamPlaybackAccessToken']["signature"] - value = responsePlaybackAccessToken["data"]['streamPlaybackAccessToken']["value"] + signature: JsonType | None = responsePlaybackAccessToken["data"].get( + 'streamPlaybackAccessToken', {}).get("signature") + value: JsonType | None = responsePlaybackAccessToken["data"].get( + 'streamPlaybackAccessToken', {}).get("value") + if not signature or not value: + logger.error( + f"Invalid response from Twitch: {responsePlaybackAccessToken}") continue # encoded_value = quote(json.dumps(value))