adding fail check on JSON getblogposts
This commit is contained in:
@@ -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'))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user