boxabhi/django_elastic_demo

TypeError at / 'NoneType' object is not iterable

cseshahriar opened this issue · 0 comments

for data in payload.get('articles'):

TypeError at /
'NoneType' object is not iterable

error

def generate_random_data():
    url = 'https://newsapi.org/v2/everything?q=apple&from=2021-04-23&to=2021-04-23&sortBy=popularity&apiKey=827705eea42e455cba8bf4afafc7da90'
    r = requests.get(url)
    payload = json.loads(r.text)
    count = 1
   
 if payload.get('articles'):  # please add this line        
    for data in payload.get('articles'):
            print(count)
            ElasticDemo.objects.create(
                title = data.get('title'),
                content = data.get('description')
            )