jenkins-bot has submitted this change and it was merged.
Change subject: Use a new FatalServerError exception for SSL certificate
failures
......................................................................
Use a new FatalServerError exception for SSL certificate failures
Failures in SSL certificate verification are unlikely to be fixed by
just retrying the request. This commit introduces a new FatalServerError
class for this (and maybe other) server error.
Change-Id: I19bf597d967e753b944bd5e7ef6c21b06bc900d7
---
M pywikibot/comms/http.py
M pywikibot/data/api.py
M pywikibot/exceptions.py
3 files changed, 18 insertions(+), 1 deletion(-)
Approvals:
Merlijn van Deen: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/comms/http.py b/pywikibot/comms/http.py
index a8dc98f..1dee9ec 100644
--- a/pywikibot/comms/http.py
+++ b/pywikibot/comms/http.py
@@ -27,8 +27,9 @@
import logging
import atexit
+from httplib2 import SSLHandshakeError
from pywikibot import config
-from pywikibot.exceptions import Server504Error
+from pywikibot.exceptions import FatalServerError, Server504Error
import pywikibot
import cookielib
import threadedhttp
@@ -38,6 +39,11 @@
# global variables
+
+# The OpenSSL error code for
+# certificate verify failed
+# cf. `openssl errstr 14090086`
+SSL_CERT_VERIFY_FAILED = ":14090086:"
# the User-agent: header. The default is
# '<script>/<revision> Pywikipediabot/2.0', where '<script>' is the currently
@@ -112,6 +118,10 @@
request.lock.acquire()
#TODO: do some error correcting stuff
+ if isinstance(request.data, SSLHandshakeError):
+ if SSL_CERT_VERIFY_FAILED in str(request.data):
+ raise FatalServerError(str(request.data))
+
#if all else fails
if isinstance(request.data, Exception):
raise request.data
diff --git a/pywikibot/data/api.py b/pywikibot/data/api.py
index 237d433..2b23fb4 100644
--- a/pywikibot/data/api.py
+++ b/pywikibot/data/api.py
@@ -289,6 +289,10 @@
pywikibot.log(u"Caught HTTP 504 error; retrying")
self.wait()
continue
+ except FatalServerError:
+ # This error is not going to be fixed by just waiting
+ pywikibot.error(traceback.format_exc())
+ raise
#TODO: what other exceptions can occur here?
except Exception, e:
# for any other error on the http request, wait and retry
diff --git a/pywikibot/exceptions.py b/pywikibot/exceptions.py
index c5a7b3f..8972fed 100644
--- a/pywikibot/exceptions.py
+++ b/pywikibot/exceptions.py
@@ -119,6 +119,9 @@
class ServerError(Error):
"""Got unexpected server response"""
+class FatalServerError(ServerError):
+ """A fatal server error that's not going to be corrected by just sending
+ the request again."""
class Server504Error(Error):
"""Server timed out with http 504 code"""
--
To view, visit https://gerrit.wikimedia.org/r/80348
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I19bf597d967e753b944bd5e7ef6c21b06bc900d7
Gerrit-PatchSet: 2
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Mineo <[email protected]>
Gerrit-Reviewer: Ladsgroup <[email protected]>
Gerrit-Reviewer: Legoktm <[email protected]>
Gerrit-Reviewer: Merlijn van Deen <[email protected]>
Gerrit-Reviewer: Mineo <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
Pywikibot-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/pywikibot-commits