jenkins-bot has submitted this change. (
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/731116 )
Change subject: [bugfix] Raise a generic ServerError if the http status code is
unofficial
......................................................................
[bugfix] Raise a generic ServerError if the http status code is unofficial
Bug: T293208
Change-Id: I3caf2d70803e25b73acada64b13281afbda50a90
---
M pywikibot/site_detect.py
1 file changed, 16 insertions(+), 1 deletion(-)
Approvals:
Matěj Suchánek: Looks good to me, but someone else must approve
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/site_detect.py b/pywikibot/site_detect.py
index 6868b52..0181f65 100644
--- a/pywikibot/site_detect.py
+++ b/pywikibot/site_detect.py
@@ -5,6 +5,8 @@
# Distributed under the terms of the MIT license.
#
import json
+import re
+
from contextlib import suppress
from html.parser import HTMLParser
from http import HTTPStatus
@@ -276,9 +278,22 @@
"""Raise ServerError if the response indicates a server error.
.. versionadded:: 3.0
+ .. versionchanged:: 7.0
+ Raise a generic ServerError if http status code is not
+ IANA-registered but unofficial code
+
+
"""
if response.status_code >= HTTPStatus.INTERNAL_SERVER_ERROR:
- raise ServerError(HTTPStatus(response.status_code).phrase)
+ try:
+ msg = HTTPStatus(response.status_code).phrase
+ except ValueError as err:
+ m = re.search(r'\d{3}', err.args[0], flags=re.ASCII)
+ if not m:
+ raise err
+ msg = 'Generic Server Error ({})'.format(m.group())
+
+ raise ServerError(msg)
if response.status_code == HTTPStatus.OK \
and SERVER_DB_ERROR_MSG in response.text:
--
To view, visit
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/731116
To unsubscribe, or for help writing mail filters, visit
https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I3caf2d70803e25b73acada64b13281afbda50a90
Gerrit-Change-Number: 731116
Gerrit-PatchSet: 3
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Matěj Suchánek <matejsuchanek97(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged