diff --git a/implementations/validator/iiif_validator/tests/baseurl_redirect.py b/implementations/validator/iiif_validator/tests/baseurl_redirect.py index b99f1a2..298d0b9 100644 --- a/implementations/validator/iiif_validator/tests/baseurl_redirect.py +++ b/implementations/validator/iiif_validator/tests/baseurl_redirect.py @@ -1,4 +1,5 @@ from .test import BaseTest, ValidatorError +import ssl try: # python3 from urllib.request import Request, urlopen, HTTPError @@ -19,11 +20,12 @@ def run(self, result): url = url.replace('/info.json', '') try: r = Request(url) - wh = urlopen(r) - img = wh.read() + context = ssl._create_unverified_context() + wh = urlopen(r, context=context) + img = wh.read() wh.close() except HTTPError as e: - wh = e + wh = e u = wh.geturl() if u == url: @@ -32,4 +34,4 @@ def run(self, result): else: # we must have redirected if our url is not what was requested result.tests.append('redirect') - return result \ No newline at end of file + return result diff --git a/implementations/validator/iiif_validator/tests/format_conneg.py b/implementations/validator/iiif_validator/tests/format_conneg.py index ac6a4ff..bb0c1da 100644 --- a/implementations/validator/iiif_validator/tests/format_conneg.py +++ b/implementations/validator/iiif_validator/tests/format_conneg.py @@ -1,4 +1,5 @@ from .test import BaseTest +import ssl try: # python3 from urllib.request import Request, urlopen, HTTPError @@ -18,8 +19,9 @@ def run(self, result): hdrs = {'Accept': 'image/png;q=1.0'} try: r = Request(url, headers=hdrs) - wh = urlopen(r) - img = wh.read() + context = ssl._create_unverified_context() + wh = urlopen(r, context=context) + img = wh.read() wh.close() except HTTPError as e: wh = e @@ -32,4 +34,4 @@ def run(self, result): result.last_status = wh.code result.urls.append(url) self.validationInfo.check('format', ct, 'image/png', result) - return result \ No newline at end of file + return result diff --git a/implementations/validator/iiif_validator/tests/format_jp2.py b/implementations/validator/iiif_validator/tests/format_jp2.py index c53b5e2..edeb224 100644 --- a/implementations/validator/iiif_validator/tests/format_jp2.py +++ b/implementations/validator/iiif_validator/tests/format_jp2.py @@ -1,5 +1,5 @@ from .test import BaseTest, ValidatorError -import magic, urllib +import magic, urllib, ssl class Test_Format_Jp2(BaseTest): label = 'JPEG2000 format' @@ -13,7 +13,8 @@ def run(self, result): params = {'format': 'jp2'} url = result.make_url(params) # Need as plain string for magic - wh = urllib.urlopen(url) + context = ssl._create_unverified_context() + wh = urllib.urlopen(url, context=context) img = wh.read() wh.close() @@ -24,4 +25,4 @@ def run(self, result): raise ValidatorError('format', info, 'JPEG 2000', result) else: result.tests.append('format') - return result \ No newline at end of file + return result diff --git a/implementations/validator/iiif_validator/tests/format_pdf.py b/implementations/validator/iiif_validator/tests/format_pdf.py index 18187b2..e5881d1 100644 --- a/implementations/validator/iiif_validator/tests/format_pdf.py +++ b/implementations/validator/iiif_validator/tests/format_pdf.py @@ -1,5 +1,5 @@ from .test import BaseTest, ValidatorError -import magic, urllib +import magic, urllib, ssl class Test_Format_Pdf(BaseTest): label = 'PDF format' @@ -13,7 +13,8 @@ def run(self, result): params = {'format': 'pdf'} url = result.make_url(params) # Need as plain string for magic - wh = urllib.urlopen(url) + context = ssl._create_unverified_context() + wh = urllib.urlopen(url, context=context) img = wh.read() wh.close() @@ -24,4 +25,4 @@ def run(self, result): raise ValidatorError('format', info, 'PDF', result) else: result.tests.append('format') - return result \ No newline at end of file + return result diff --git a/implementations/validator/iiif_validator/tests/format_webp.py b/implementations/validator/iiif_validator/tests/format_webp.py index 8937358..2281a7b 100644 --- a/implementations/validator/iiif_validator/tests/format_webp.py +++ b/implementations/validator/iiif_validator/tests/format_webp.py @@ -1,5 +1,5 @@ from .test import BaseTest, ValidatorError -import urllib +import urllib, ssl class Test_Format_Webp(BaseTest): label = 'WebP format' @@ -14,11 +14,12 @@ def run(self, result): params = {'format': 'webp'} url = result.make_url(params) # Need as plain string for magic - wh = urllib.urlopen(url) + context = ssl._create_unverified_context() + wh = urllib.urlopen(url, context=context) img = wh.read() wh.close() if img[8:12] != "WEBP": raise ValidatorError('format', 'unknown', 'WEBP', result) else: result.tests.append('format') - return result \ No newline at end of file + return result diff --git a/implementations/validator/iiif_validator/tests/jsonld.py b/implementations/validator/iiif_validator/tests/jsonld.py index 65a45dd..5d4b97d 100644 --- a/implementations/validator/iiif_validator/tests/jsonld.py +++ b/implementations/validator/iiif_validator/tests/jsonld.py @@ -1,4 +1,5 @@ from .test import BaseTest +import ssl try: # python3 from urllib.request import Request, urlopen, HTTPError @@ -18,11 +19,12 @@ def run(self, result): hdrs = {'Accept': 'application/ld+json'} try: r = Request(url, headers=hdrs) - wh = urlopen(r) - img = wh.read() + context = ssl._create_unverified_context() + wh = urlopen(r, context=context) + img = wh.read() wh.close() except HTTPError as e: wh = e ct = wh.headers['content-type'] self.validationInfo.check('json-ld', ct.startswith('application/ld+json'), 1, result, "Content-Type to start with application/ld+json") - return result \ No newline at end of file + return result diff --git a/implementations/validator/iiif_validator/validator.py b/implementations/validator/iiif_validator/validator.py index 4f7e8ef..8451741 100644 --- a/implementations/validator/iiif_validator/validator.py +++ b/implementations/validator/iiif_validator/validator.py @@ -7,6 +7,7 @@ import sys import random import os +import ssl try: # python2 import BytesIO as io # Must check for python2 first as io exists but is wrong one @@ -260,9 +261,9 @@ def fetch(self, url): "Referer": "http://iiif.io/api/image/validator", "User-Agent": "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1b3pre) Gecko/20081130 Minefield/3.1b3pre"} req = Request(url, headers=HEADERS) - + context = ssl._create_unverified_context() try: - wh = urlopen(req, timeout=5) + wh = urlopen(req, timeout=5, context=context) except HTTPError as e: wh = e except: