jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/567213 )
Change subject: [bugfix] Fix UnboundLocalError in ProofreadPage._ocr_callback ......................................................................
[bugfix] Fix UnboundLocalError in ProofreadPage._ocr_callback
- use for statement instead of while - return if loop is processed completely with 5 retries and do not continue the method because response is not fetched - move sleep statement out of exception handling; probably other exceptions can also have retries in future
Bug: T243644 Change-Id: Id3601ea4678a3a0ab158a942644d792e46c7cea5 --- M pywikibot/proofreadpage.py 1 file changed, 7 insertions(+), 5 deletions(-)
Approvals: Dvorapa: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/proofreadpage.py b/pywikibot/proofreadpage.py index 5ca3dfd..662cba0 100644 --- a/pywikibot/proofreadpage.py +++ b/pywikibot/proofreadpage.py @@ -599,17 +599,14 @@ (self._OCR_METHODS, ocr_tool))
# wrong link fail with Exceptions - retry = 0 - while retry < 5: + for retry in range(5, 30, 5): pywikibot.debug('{0}: get URI {1!r}'.format(ocr_tool, cmd_uri), _logger) try: response = http.fetch(cmd_uri) except requests.exceptions.ReadTimeout as e: - retry += 1 + timeout = e pywikibot.warning('ReadTimeout %s: %s' % (cmd_uri, e)) - pywikibot.warning('retrying in %s seconds ...' % (retry * 5)) - time.sleep(retry * 5) except Exception as e: pywikibot.error('"%s": %s' % (cmd_uri, e)) return (True, e) @@ -618,6 +615,11 @@ _logger) break
+ pywikibot.warning('retrying in {} seconds ...'.format(retry)) + time.sleep(retry) + else: + return True, timeout + if 400 <= response.status < 600: return (True, 'Http response status {0}'.format(response.status))
pywikibot-commits@lists.wikimedia.org