From 2790342a095619fef8ab715805e919d1bac83cb0 Mon Sep 17 00:00:00 2001 From: Alexander Graf <17130992+aandergr@users.noreply.github.com> Date: Wed, 25 Mar 2020 18:17:02 +0100 Subject: [PATCH] Catch KeyError: 'authenticated' when Logging In Fixes #472. --- instaloader/instaloadercontext.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/instaloader/instaloadercontext.py b/instaloader/instaloadercontext.py index c327286..24305b0 100644 --- a/instaloader/instaloadercontext.py +++ b/instaloader/instaloadercontext.py @@ -239,6 +239,12 @@ class InstaloaderContext: resp_json['message'])) else: raise ConnectionException("Login error: \"{}\" status.".format(resp_json['status'])) + if 'authenticated' not in resp_json: + # Issue #472 + if 'message' in resp_json: + raise ConnectionException("Login error: Unexpected response, \"{}\".".format(resp_json['message'])) + else: + raise ConnectionException("Login error: Unexpected response, this might indicate a blocked IP.") if not resp_json['authenticated']: if resp_json['user']: # '{"authenticated": false, "user": true, "status": "ok"}'