jenkins-bot has submitted this change and it was merged.
Change subject: Add ability to ignore SSL certificate errors ......................................................................
Add ability to ignore SSL certificate errors
The following registered families have HTTPS, but there are SSL certificate errors: - lockwiki - omegawiki - vikidia
HTTPS is enabled for those families, with SSL cert errors ignored.
Bug: 68794 Change-Id: Ifd33bc2ac60a268f6fad2770c18ecd0ebc5a2b6d --- M pywikibot/comms/http.py M pywikibot/comms/threadedhttp.py M pywikibot/families/lockwiki_family.py M pywikibot/families/omegawiki_family.py M pywikibot/families/vikidia_family.py M pywikibot/family.py 6 files changed, 47 insertions(+), 2 deletions(-)
Approvals: John Vandenberg: Looks good to me, but someone else must approve XZise: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/comms/http.py b/pywikibot/comms/http.py index f2f6eaa..69fb686 100644 --- a/pywikibot/comms/http.py +++ b/pywikibot/comms/http.py @@ -234,6 +234,9 @@ else: host = site.hostname() baseuri = urlparse.urljoin("%s://%s" % (proto, host), uri) + + kwargs.setdefault("disable_ssl_certificate_validation", + site.ignore_certificate_error()) else: baseuri = uri
diff --git a/pywikibot/comms/threadedhttp.py b/pywikibot/comms/threadedhttp.py index 790190b..7d0b632 100644 --- a/pywikibot/comms/threadedhttp.py +++ b/pywikibot/comms/threadedhttp.py @@ -350,6 +350,11 @@ if item is None: pywikibot.debug(u"Shutting down thread.", _logger) return + + # This needs to be set per request, however it is only used + # the first time the pooled connection is created. + self.http.disable_ssl_certificate_validation = \ + item.kwargs.pop('disable_ssl_certificate_validation', False) try: item.data = self.http.request(*item.args, **item.kwargs) finally: @@ -459,7 +464,7 @@ self.response.get(k.lower(), None) if k not in self.response: return [] - #return self.response[k].split(re.compile(',\s*')) + # return self.response[k].split(re.compile(',\s*'))
# httplib2 joins multiple values for the same header # using ','. but the netscape cookie format uses ',' diff --git a/pywikibot/families/lockwiki_family.py b/pywikibot/families/lockwiki_family.py index 3b30fba..0a4d0a4 100644 --- a/pywikibot/families/lockwiki_family.py +++ b/pywikibot/families/lockwiki_family.py @@ -30,3 +30,11 @@ def nicepath(self, code): """Return the nice article path for this family.""" return "%s/" % self.path(self, code) + + def protocol(self, code): + """Return https as the protocol for this family.""" + return "https" + + def ignore_certificate_error(self, code): + """Ignore certificate errors.""" + return True # has a different domain in its certificate. diff --git a/pywikibot/families/omegawiki_family.py b/pywikibot/families/omegawiki_family.py index aa234c5..7661dac 100644 --- a/pywikibot/families/omegawiki_family.py +++ b/pywikibot/families/omegawiki_family.py @@ -40,3 +40,11 @@ def apipath(self, code): """Return the path to api.php for this family.""" return '/api.php' + + def protocol(self, code): + """Return https as the protocol for this family.""" + return "https" + + def ignore_certificate_error(self, code): + """Ignore certificate errors.""" + return True # has an expired certificate. diff --git a/pywikibot/families/vikidia_family.py b/pywikibot/families/vikidia_family.py index 4428479..e02e803 100644 --- a/pywikibot/families/vikidia_family.py +++ b/pywikibot/families/vikidia_family.py @@ -51,3 +51,11 @@ # Most wikis nowadays use UTF-8, but change this if yours uses # a different encoding return 'utf-8' + + def protocol(self, code): + """Return https as the protocol for this family.""" + return "https" + + def ignore_certificate_error(self, code): + """Ignore certificate errors.""" + return True # has self-signed certificate for a different domain. diff --git a/pywikibot/family.py b/pywikibot/family.py index d2e6a6d..9549657 100644 --- a/pywikibot/family.py +++ b/pywikibot/family.py @@ -917,7 +917,9 @@ # Methods def protocol(self, code): """ - Can be overridden to return 'https'. Other protocols are not supported. + The protocol to use to connect to the site. + + May be overridden to return 'https'. Other protocols are not supported.
@param code: language code @type code: string @@ -926,6 +928,17 @@ """ return 'http'
+ def ignore_certificate_error(self, code): + """ + Return whether a HTTPS certificate error should be ignored. + + @param code: language code + @type code: string + @return: flag to allow access if certificate has an error. + @rtype: bool + """ + return False + def hostname(self, code): """The hostname to use for standard http connections.""" return self.langs[code]