diff options
author | Jelle van der Waa <jelle@archlinux.org> | 2020-03-05 21:22:17 +0100 |
---|---|---|
committer | Jelle van der Waa <jelle@archlinux.org> | 2020-03-05 21:28:37 +0100 |
commit | 6c796fce1d0928112f83ea01efe95ab3d24d7fa9 (patch) | |
tree | dc00185bd159c9b530c44281ee7b9ebc2c465cdd | |
parent | c41b3dacc7915bf11f5b151bdc2cffea6c5ae659 (diff) | |
download | archweb-6c796fce1d0928112f83ea01efe95ab3d24d7fa9.tar.gz archweb-6c796fce1d0928112f83ea01efe95ab3d24d7fa9.zip |
planet: handle response without 'status'
feedparser's parse method returns an arbitrary dictionary which may or
may not have the HTTP status. Rely on get() to return None if it's
lacking and then return and log a message.
-rw-r--r-- | planet/management/commands/update_planet.py | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/planet/management/commands/update_planet.py b/planet/management/commands/update_planet.py index fd74c291..19ee7494 100644 --- a/planet/management/commands/update_planet.py +++ b/planet/management/commands/update_planet.py @@ -54,15 +54,19 @@ class Command(BaseCommand): etag = cache.get(f'planet:etag:{url}') feed = feedparser.parse(url, etag=etag) + http_status = feed.get('status') - if feed['status'] == 304: + if not http_status: + logger.info("The feed '%s' returns no HTTP status", url) + + if http_status == 304: logger.info("The feed '%s' has not changed since we last checked it", url) if 'etag' in feed: cache.set(f'planet:etag:{url}', feed.etag, 86400) return - if feed['status'] != 200: - logger.info("error parsing feed: '%s', status: '%s'", url, feed['status']) + if http_status != 200: + logger.info("error parsing feed: '%s', status: '%s'", url, http_status) return if not feed.entries: |