Protect against HTTP error codes

This commit is contained in:
Stephane Bortzmeyer 2022-07-07 10:44:04 +02:00
parent b76364682c
commit 2ec088b74d
1 changed files with 4 additions and 1 deletions

View File

@ -20,7 +20,7 @@ import shutil
# http://python-requests.org/
import requests
PRESTO_URL = "http://www.sidc.be/archive/product/presto"
PRESTO_URL = "https://www.sidc.be/archive/product/presto"
SOURCE_URL = "https://forge.chapril.org/bortzmeyer/presto2gemini"
# Defaults
@ -129,6 +129,9 @@ if not dest_dir.endswith("/"):
input_ok = False
if input is None:
r = requests.get(url, allow_redirects = False)
if r.status_code != 200:
print("Wrong status code %s from %s" % (r.status_code, PRESTO_URL), file=sys.stderr)
sys.exit(1)
if r.status_code == 200 and r.text != "" and r.text != "\r\n" and r.text != "\n": # Yes,
# when there is no alert, they reply with 200 and an empty file :-(
raw = open("%s%s" % (raw_file_dir, date), "w")