jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1045721?usp=email )
Change subject: [IMPR] No longer wait in Requests._http_request for ImportError and NameError ......................................................................
[IMPR] No longer wait in Requests._http_request for ImportError and NameError
Neither ImportError nor NameError can eb fixed by just waiting and retry. raise the exception and leave in such case
Change-Id: I087b6c3106fd625036e719a1a371a7d3080215e5 --- M pywikibot/comms/http.py M pywikibot/data/api/_requests.py 2 files changed, 20 insertions(+), 5 deletions(-)
Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/comms/http.py b/pywikibot/comms/http.py index ef4cc61..a61d464 100644 --- a/pywikibot/comms/http.py +++ b/pywikibot/comms/http.py @@ -432,8 +432,10 @@ auth = get_authentication(uri) if auth is not None and len(auth) == 4: if isinstance(requests_oauthlib, ImportError): - pywikibot.error(requests_oauthlib) - sys.exit(1) + raise ModuleNotFoundError(f"""{requests_oauthlib}. Install it with + + pip install requests_oauthlib +""") else: auth = requests_oauthlib.OAuth1(*auth)
diff --git a/pywikibot/data/api/_requests.py b/pywikibot/data/api/_requests.py index 8ce916d..b5c4d5c 100644 --- a/pywikibot/data/api/_requests.py +++ b/pywikibot/data/api/_requests.py @@ -13,6 +13,7 @@ import pickle import pprint import re +import sys import traceback from collections.abc import MutableMapping from contextlib import suppress @@ -670,9 +671,12 @@ .. versionchanged:: 8.2 change the scheme if the previous request didn't have json content. + .. versionchanged:: 9.2 + no wait cycles for :exc:`ImportError` and :exc:`NameError`.
:return: a tuple containing requests.Response object from http.request and use_get value + :meta public: """ kwargs = {} schemes = ('http', 'https') @@ -686,6 +690,7 @@ data=data, headers=headers, **kwargs) except Server504Error: pywikibot.log('Caught HTTP 504 error; retrying') + except Client414Error: if use_get: pywikibot.log('Caught HTTP 414 error; retrying') @@ -694,17 +699,25 @@ pywikibot.warning( 'Caught HTTP 414 error, although not using GET.') raise - except (ConnectionError, FatalServerError): - # This error is not going to be fixed by just waiting - pywikibot.error(traceback.format_exc()) + + except (ConnectionError, FatalServerError, NameError): + # These errors are not going to be fixed by just waiting raise + + except ImportError as e: + # Leave the script gracefully + pywikibot.error(e) + sys.exit(1) + # TODO: what other exceptions can occur here? except Exception: # for any other error on the http request, wait and retry pywikibot.error(traceback.format_exc()) pywikibot.log(f'{uri}, {paramstring}') + else: return response, use_get + self.wait() return None, use_get
pywikibot-commits@lists.wikimedia.org