From 8fc9d197cf3629742015b88575c98c4e0998e48f Mon Sep 17 00:00:00 2001 From: jake Date: Mon, 25 Mar 2024 14:48:52 -0700 Subject: [PATCH] Added support for cases where there is no Last-Modified header (e.g. testing) --- internetarchive/files.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/internetarchive/files.py b/internetarchive/files.py index 3ddcfa98..848aa8ad 100644 --- a/internetarchive/files.py +++ b/internetarchive/files.py @@ -300,10 +300,13 @@ def download(self, file_path=None, verbose=None, ignore_existing=None, raise exc # Get timestamp from Last-Modified header - time_str = response.headers["Last-Modified"] - last_updated_pattern = "%a, %d %b %Y %H:%M:%S %Z" - dt = datetime.strptime(time_str, last_updated_pattern).replace(tzinfo=timezone.utc) - last_modified = int(dt.timestamp()) + try: + time_str = response.headers["Last-Modified"] + last_updated_pattern = "%a, %d %b %Y %H:%M:%S %Z" + dt = datetime.strptime(time_str, last_updated_pattern).replace(tzinfo=timezone.utc) + last_modified = int(dt.timestamp()) + except KeyError: + last_modified = 0 # Set mtime with mtime from files.xml. if not no_change_timestamp: