From 841ac345bd16da03b4774e6ffcde8f49c8f79747 Mon Sep 17 00:00:00 2001 From: Jack Gilmore <46202639+JackGilmore@users.noreply.github.com> Date: Sat, 6 Jul 2024 16:19:12 +0000 Subject: [PATCH] Quick patch to fix Angus SSL issues --- .github/workflows/alive.yml | 2 +- tools/alive.py | 15 ++++++++++++++- tools/requirements.txt | 1 + 3 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 tools/requirements.txt diff --git a/.github/workflows/alive.yml b/.github/workflows/alive.yml index 55df1058..a4ab9708 100644 --- a/.github/workflows/alive.yml +++ b/.github/workflows/alive.yml @@ -20,7 +20,7 @@ jobs: python-version: '3.9' - name: Set up environment run: | - pip install pygithub + pip install -r requirements.txt - name: Run status checker env: GITHUB_ACCESS_TOKEN: ${{secrets.ALIVE_GITHUB_TOKEN}} diff --git a/tools/alive.py b/tools/alive.py index 133339ef..78b5362b 100755 --- a/tools/alive.py +++ b/tools/alive.py @@ -7,11 +7,14 @@ import csv import os import time +import ssl GITHUB_REPO = "OpenDataScotland/the_od_bods" def handle_error(row): + print(f"HANDLING ERROR for {row['Name']}") + return issue_body = "**Broken URL:** [#{}]({})\n\n".format( row["Source URL"], row["Source URL"] ) @@ -75,8 +78,18 @@ def handle_error(row): print(f"Polling {url}") req = Request(url) + + ctx = ssl.create_default_context() + + # Ignoring SSL checks for Angus because their SSL cert is broken + # TODO: Contact Angus Council to notify them their SSL cert is broken. Remove this once fixed. + if row["Name"] == "Angus Council": + print("Ignoring SSL checks for this domain") + ctx.check_hostname = False + ctx.verify_mode = ssl.CERT_NONE + try: - response = urlopen(req) + response = urlopen(req, context=ctx) print(f"Got status code {response.getcode()} for {req.full_url}") except HTTPError as e: print(f"Got status code {e.code} for {req.full_url}") diff --git a/tools/requirements.txt b/tools/requirements.txt new file mode 100644 index 00000000..02cc6449 --- /dev/null +++ b/tools/requirements.txt @@ -0,0 +1 @@ +PyGithub==2.3.0 \ No newline at end of file