Page MenuHomePhabricator

unchecked response dict access in pywikibot
Closed, DuplicatePublicBUG REPORT

Description

List of steps to reproduce (step by step, including full links if applicable):
Try to access a site via pywikbot login manager where there is a login failure

What happens?:

 File "/Users/wf/Library/Python/3.9/lib/python/site-packages/pywikibot/data/api.py", line 3052, in getCookie
    and (response['messagecode'] == 'login-throttled'
KeyError: 'messagecode'

What should have happened instead?:

The code should run without a KeyError e.g. by changing the code to

if (status == 'Throttled' or status == self.keyword('fail')
               and ('messagecode' in response and response['messagecode'] == 'login-throttled'
                    or 'wait' in fail_reason)):

and maybe throw the correct exception such as: pywikibot.exceptions.NoUsername

Software version (if not a Wikimedia wiki), browser information, screenshots, other information, etc:
pywikibot 6.6.3

Event Timeline