#python #python-3.x #indexoutofboundsexception #medium.com
#python #python-3.x #исключение indexoutofboundsexception #medium.com-publishing-api
Вопрос:
Я использую API medium для получения некоторой информации, но после некоторых вызовов API скрипт python завершился с этой ошибкой:
Ошибка индекса: индекс списка вне диапазона
Вот мой код на Python:
def get_post_responses(posts):
#start = time.time()
count = 0
print('Retrieving the post responses...')
responses = []
for post in posts:
url = MEDIUM '/_/api/posts/' post '/responses'
count = count 1
print("number of times api called",count)
response = requests.get(url)
response_dict = clean_json_response(response)
responses = response_dict['payload']['value']
#end = time.time()
#four = end - start
#global time_cal
#time_cal.append(four)
return responses
def check_if_high_recommends(response, recommend_min):
if response['virtuals']['recommends'] >= recommend_min:
return True
def check_if_recent(response):
limit_date = datetime.now() - timedelta(days=360)
creation_epoch_time = response['createdAt'] / 1000
creation_date = datetime.fromtimestamp(creation_epoch_time)
if creation_date >= limit_date:
return True
Она должна работать для более чем 10000 подписчиков для пользователя.
Комментарии:
1. Какая строка выдает исключение?
Ответ №1:
я получил ответ на свой вопрос… просто мне нужно использовать исключение try catch …
response_dict = clean_json_response(response)
try:
responses = response_dict['payload']['value']
catch:
continue