Commit 45ce1ecc authored by fred's avatar fred

load-from-drupal-json: handle errors when loading remote images

parent 8c5f27e0
......@@ -60,12 +60,16 @@ class Command(BaseCommand):
if default_storage.exists(orig_path):
path = orig_path
else:
path = default_storage.save(
'images/%s/%s' % (
emission.slug,
episode_data.get('image').split('/')[-1]),
ContentFile(requests.get(episode_data.get('image')).content))
episode.image = default_storage.open(path)
episode.image = None
episode.save()
response = requests.get(episode_data.get('image'))
if response.status_code == 200:
path = default_storage.save(
'images/%s/%s' % (
emission.slug,
episode_data.get('image').split('/')[-1]),
ContentFile(response.content))
episode.image = default_storage.open(path)
try:
episode.save()
except OSError: # OSError: cannot identify image file
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment