Skip to content

Commit 6c796fc

Browse files
committed
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.
1 parent c41b3da commit 6c796fc

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

planet/management/commands/update_planet.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,19 @@ def parse_feed(self, feed_instance):
5454

5555
etag = cache.get(f'planet:etag:{url}')
5656
feed = feedparser.parse(url, etag=etag)
57+
http_status = feed.get('status')
5758

58-
if feed['status'] == 304:
59+
if not http_status:
60+
logger.info("The feed '%s' returns no HTTP status", url)
61+
62+
if http_status == 304:
5963
logger.info("The feed '%s' has not changed since we last checked it", url)
6064
if 'etag' in feed:
6165
cache.set(f'planet:etag:{url}', feed.etag, 86400)
6266
return
6367

64-
if feed['status'] != 200:
65-
logger.info("error parsing feed: '%s', status: '%s'", url, feed['status'])
68+
if http_status != 200:
69+
logger.info("error parsing feed: '%s', status: '%s'", url, http_status)
6670
return
6771

6872
if not feed.entries:

0 commit comments

Comments
 (0)