[gimp-web] tools: mirror check script to use HTTP request with headers.
- From: Jehan <jehanp src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp-web] tools: mirror check script to use HTTP request with headers.
- Date: Sat, 30 Apr 2022 20:11:10 +0000 (UTC)
commit 7f4eeecffbc7be314788d0863ef981c8d7cea1ee
Author: Jehan <jehan girinstud io>
Date: Sat Apr 30 22:06:33 2022 +0200
tools: mirror check script to use HTTP request with headers.
We had one mirror (Jaleco) which was consistently returning a 403
(Forbidden) error when --verify-checksum was set. It seems that it
didn't like the request, lacking proper header. So let's add the
User-Agent which seems to be enough to get it working.
Additionally when checking the files validity with this option, we are
doing a full download, no need to make the requests.head() test first.
It's redundant.
tools/downloads/gimp-check-mirrors.py | 18 ++++++++++--------
1 file changed, 10 insertions(+), 8 deletions(-)
---
diff --git a/tools/downloads/gimp-check-mirrors.py b/tools/downloads/gimp-check-mirrors.py
index 7efdc8e2..041169f7 100755
--- a/tools/downloads/gimp-check-mirrors.py
+++ b/tools/downloads/gimp-check-mirrors.py
@@ -7,6 +7,7 @@ import fileinput
import hashlib
import re
import requests
+import urllib.request
from urllib.error import HTTPError, URLError
from urllib.request import urlretrieve, urlopen
import sys
@@ -131,11 +132,10 @@ for local_uri in local_uris:
check_count += 1
try:
- response = requests.head(url=mirror_uri, timeout=20, allow_redirects=True)
-
- checksum_text = ''
if args.verify_checksum:
- with urlopen(mirror_uri, timeout = 5.0) as remote_file:
+ request = urllib.request.Request(mirror_uri, headers={'User-Agent': 'Mozilla/5.0'})
+ with urlopen(request, timeout = 5.0) as remote_file:
+ checksum_text = ''
m = hashlib.sha256()
m.update(remote_file.read())
if m.digest() == origin_sum.digest():
@@ -143,10 +143,12 @@ for local_uri in local_uris:
else:
checksum_text = ' (checksum KO)'
error_count += 1
-
- print(str(response.status_code) + ' : ' + mirror_uri + checksum_text)
- if response.status_code != 200:
- error_count += 1
+ print(str(remote_file.status) + ' : ' + mirror_uri + checksum_text)
+ else:
+ response = requests.head(url=mirror_uri, timeout=20, allow_redirects=True)
+ print(str(response.status_code) + ' : ' + mirror_uri)
+ if response.status_code != 200:
+ error_count += 1
except HTTPError as error:
error_count += 1
print(str(error.code) + ' : ' + mirror_uri)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]