[help.gnome.org: 13/14] Handle urllib.request exceptions




commit c0d8eb6afdec9ed98c3b567a0fe74745255839da
Author: Emmanuele Bassi <ebassi gnome org>
Date:   Tue Nov 23 22:07:27 2021 +0000

    Handle urllib.request exceptions
    
    We're getting 404s when cloning all repositories; instead of just dying,
    print out where we failed.

 configger.py | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
---
diff --git a/configger.py b/configger.py
index b237c27..47ae03a 100755
--- a/configger.py
+++ b/configger.py
@@ -39,10 +39,14 @@ try:
                     project = 'GNOME'
                 repository = 'https://gitlab.gnome.org/' + project + '/' + app + '.git'
                 if stable is None or unstable is None:
-                    bfile = urllib.request.urlopen('https://gitlab.gnome.org/api/v4/projects/' +
-                                                   project + '%2F' + app + '/repository/branches')
-                    branches = json.load(bfile)
-                    branches = [branch['name'] for branch in branches]
+                    try:
+                        branches_url = 
f"https://gitlab.gnome.org/api/v4/projects/{project}%2F{app}/repository/branches";
+                        bfile = urllib.request.urlopen(branches_url)
+                        branches = json.load(bfile)
+                        branches = [branch['name'] for branch in branches]
+                    except urllib.error.HTTPError as err:
+                        print(f"Unable to get list of branches for {project}/{app} at {branches_url}: {err}")
+                        branches = ['master']
                     if unstable is None:
                         unstable = 'main' if ('main' in branches) else 'master'
                     if stable is None:


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]