jenkins-bot submitted this change.

View Change

Approvals: jenkins-bot: Verified Xqt: Looks good to me, approved
Remove protocol swapping in api.Request

Switches causing HTTP 403. Remove prtotocol swapping;
Family file must provide the right protocol.

Bug: T414369
Change-Id: I1234567890abcdef1234567890abcdef12345678
---
M ROADMAP.rst
M pywikibot/data/api/_requests.py
2 files changed, 4 insertions(+), 18 deletions(-)

diff --git a/ROADMAP.rst b/ROADMAP.rst
index 363fc31..4111ff9 100644
--- a/ROADMAP.rst
+++ b/ROADMAP.rst
@@ -90,6 +90,8 @@

**Other breaking changes**

+* Protocol swapping in :class:`data.api.Request` was removed. Family files should provide
+ the correct protocol. (:phab:`T414369`)
* Package requirements were updated (``beautifulsoup4``, ``fake-useragent``, ``mwoauth``,
``mwparserfromhell``, ``packaging``, ``Pillow``, ``pydot``, ``PyMySQL``, ``python-stdnum``,
``requests``, ``requests-sse``, ``wikitextparser``)
diff --git a/pywikibot/data/api/_requests.py b/pywikibot/data/api/_requests.py
index 9ec54dd..fe20032 100644
--- a/pywikibot/data/api/_requests.py
+++ b/pywikibot/data/api/_requests.py
@@ -21,7 +21,7 @@
from email.mime.nonmultipart import MIMENonMultipart
from pathlib import Path
from typing import TYPE_CHECKING, Any, NoReturn
-from urllib.parse import unquote, urlencode, urlparse
+from urllib.parse import unquote, urlencode
from warnings import warn

import pywikibot
@@ -725,16 +725,10 @@

:meta public:
"""
- kwargs = {}
- schemes = ('http', 'https')
- if self.json_warning and self.site.protocol() in schemes:
- # retry with other scheme
- kwargs['protocol'] = schemes[self.site.protocol() == 'http']
-
try:
response = http.request(self.site, uri=uri,
method='GET' if use_get else 'POST',
- data=data, headers=headers, **kwargs)
+ data=data, headers=headers)
except Server504Error:
pywikibot.log('Caught HTTP 504 error; retrying')

@@ -838,16 +832,6 @@
self[param] = [str(math.ceil(value / 2))]
pywikibot.info(f'Set {param} = {self[param]}')
else:
- scheme = urlparse(response.url).scheme
- if self.json_warning and scheme != self.site.protocol():
- warn(f"""
-Your {self.site.family} family uses a wrong scheme {self.site.protocol()!r}
-but {scheme!r} is required. Please add the following code to your family file:
-
- def protocol(self, code: str) -> str:
- return '{scheme}'
-
-""", stacklevel=2)
return result or {}

self.wait()

To view, visit change 1225635. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-MessageType: merged
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I1234567890abcdef1234567890abcdef12345678
Gerrit-Change-Number: 1225635
Gerrit-PatchSet: 16
Gerrit-Owner: Akaza24 <kesharwaniadarsh335@gmail.com>
Gerrit-Reviewer: Xqt <info@gno.de>
Gerrit-Reviewer: jenkins-bot