Based on T102602 and use test.orain.org for testing.
> import pywikibot > site = pywikibot.Site() > from pywikibot.login import OauthLoginManager > consumer_token = ('XXXXXXXXXXXXXXXXXXXXXXXXXX', 'XXXXXXXXXXXXXXXXXXXXXXXXXX') > login_manager = OauthLoginManager(consumer_token, site) > login_manager.login() Logging in to oraintest:en via OAuth consumer XXXXXXXXXXXXXXXXXXXXXXXXXX Authenticate via web browser Response query string: XXXXXXXXXXXXXXXXXXXXXXXXXX ERROR: [('SSL routines', 'SSL23_GET_SERVER_HELLO', 'sslv3 alert handshake failure')]
The exception is actually raised by complete function in mwoauth (use mwoauth 0.2.4):
def complete(mw_uri, consumer_token, request_token, response_qs): """ Completes an OAuth handshake with MediaWiki by exchanging an :Parameters: mw_uri : `str` The base URI of the MediaWiki installation. Note that the URI should end in ``"index.php"``. consumer_token : :class:`~mwoauth.ConsumerToken` A key/secret pair representing you, the consumer. request_token : :class:`~mwoauth.RequestToken` A temporary token representing the user. Returned by `initiate()`. response_qs : `bytes` The query string of the URL that MediaWiki forwards the user back after authorization. :Returns: An `AccessToken` containing an authorized key/secret pair that can be stored and used by you. """ ...... # Construct a new auth with the verifier auth = OAuth1(consumer_token.key, client_secret=consumer_token.secret, resource_owner_key=request_token.key, resource_owner_secret=request_token.secret, verifier=verifier) # Send the verifier and ask for an authorized resource owner key/secret r = requests.post(url=mw_uri, params={'title': "Special:OAuth/token"}, auth=auth) ......
The exception is raised by the last r = requests.post(...)sentence.
Also, the actual exception is hided because of T105767.
The issue may be related: https://github.com/kennethreitz/requests/issues/2022
Workaround
SNI is the reason for the error, like @Tgr mentioned in his comments:
Looking at the SSLLabs analyses:
- https://www.ssllabs.com/ssltest/analyze.html?d=en.wikipedia.org&s=208.80.154.224&hideResults=on
- https://www.ssllabs.com/ssltest/analyze.html?d=test.orain.org&s=2400%3acb00%3a2048%3a1%3a0%3a0%3a681c%3a548&hideResults=on&latest
the main differences are that Orain uses SNI and only supports elliptic ciphers, while Wikimedia crams all its domains in a single certificate and has a bunch of fallback ciphers. SNI could be the reason for the error: (1) (2) (3) (although the error messages mentioned there are different)
(1) of comments above mentions the solution: http://docs.python-requests.org/en/latest/community/faq/#what-are-hostname-doesn-t-match-errors