Private
Public Access
1
0

adding fail check on JSON getblogposts

This commit is contained in:
Sander Roosendaal
2020-06-24 08:48:01 +02:00
parent 3459ca3bb7
commit 59f93cd908

View File

@@ -7,6 +7,8 @@ import requests
import datetime
import arrow
from json.decoder import JSONDecodeError
PY3K = sys.version_info >= (3,0)
from django.core.management.base import BaseCommand
@@ -19,7 +21,10 @@ class Command(BaseCommand):
response = requests.get(
'https://analytics.rowsandall.com/wp-json/wp/v2/posts?per_page=3')
if response.status_code == 200:
blogs_json = response.json()
try:
blogs_json = response.json()
except JSONDecodeError:
blogs_json = []
else:
blogs_json = []
except ConnectionError:
@@ -46,4 +51,3 @@ class Command(BaseCommand):
self.stdout.write(self.style.SUCCESS(
'Successfully processed blog posts'))