Merlijn van Deen has uploaded a new change for review.
https://gerrit.wikimedia.org/r/234018
Change subject: Enable OAuth in http layer.
......................................................................
Enable OAuth in http layer.
This re-adds comms/http.py from
8624ddec140253ec46e0f39c1f5bdb05184840ff, which was reverted
in 2c819cabc720ec9f2e9896dbee36d5024c88eee6.
Change-Id: Id222e1b93a95ce25795e4cb4af6b4b90ef13a770
---
M pywikibot/comms/http.py
1 file changed, 22 insertions(+), 4 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core
refs/changes/18/234018/1
diff --git a/pywikibot/comms/http.py b/pywikibot/comms/http.py
index ff0c4f3..39d4d4a 100644
--- a/pywikibot/comms/http.py
+++ b/pywikibot/comms/http.py
@@ -31,6 +31,11 @@
import requests
+try:
+ import requests_oauthlib
+except ImportError as e:
+ requests_oauthlib = e
+
if sys.version_info[0] > 2:
from http import cookiejar as cookielib
from urllib.parse import quote
@@ -69,8 +74,6 @@
pywikibot.debug(u"Loading cookies failed.", _logger)
else:
pywikibot.debug(u"Loaded cookies from file.", _logger)
-
-session.cookies = cookie_jar
# Prepare flush on quit
@@ -257,7 +260,7 @@
for i in range(len(netloc_parts))]
for path in netlocs:
if path in config.authenticate:
- if len(config.authenticate[path]) == 2:
+ if len(config.authenticate[path]) in [2, 4]:
return config.authenticate[path]
else:
warn('Invalid authentication tokens for %s '
@@ -273,10 +276,25 @@
if PY2 and headers:
headers = dict((key, str(value)) for key, value in headers.items())
auth = get_authentication(uri)
+ if auth is not None and len(auth) == 4:
+ if isinstance(requests_oauthlib, ImportError):
+ warn('%s' % requests_oauthlib, ImportWarning)
+ pywikibot.error('OAuth authentication not supported: %s'
+ % requests_oauthlib)
+ auth = None
+ else:
+ auth = requests_oauthlib.OAuth1(*auth)
+ cookies = cookie_jar
timeout = config.socket_timeout
try:
+ ignore_validation = http_request.kwargs.pop(
+ 'disable_ssl_certificate_validation', False)
+ # Note that the connections are pooled which mean that a future
+ # HTTPS request can succeed even if the certificate is invalid and
+ # verify=True, when a request with verify=False happened before
response = session.request(method, uri, data=body, headers=headers,
- auth=auth, timeout=timeout, verify=True)
+ cookies=cookies, auth=auth, timeout=timeout,
+ verify=not ignore_validation)
except Exception as e:
http_request.data = e
else:
--
To view, visit https://gerrit.wikimedia.org/r/234018
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Id222e1b93a95ce25795e4cb4af6b4b90ef13a770
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Merlijn van Deen <[email protected]>
Gerrit-Reviewer: VcamX <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits