pwb.py: Limit the try clause to the minimum amount of code necessary
pwb.py: Limit the try clause to the minimum amount of code necessary

This avoids masking bugs and makes the code easier to understand.

Change-Id: Ia16fe15018b0d5adcc8459854b80f54cb6bfe55e

wikimedia/pywikibot-core,wikimedia/pywikibot-core,PersianWikipedia/pywikibot-core