I keep encountering this issue with my code
response_result = {}
formatted_response = {}
query = sql_trend.format(login_id, aggregation_filter, number_of_week_months - 1, date_value(aggregation_filter, aggregation_filter_value, year))
response = execute_query(query, transaction_id, False)
for row in response.get('message'):
current_list = ast.literal_eval(row)
owner, state, count, week = (current_list[0], current_list[1], current_list[2], current_list[3])
if owner in formatted_response:
formatted_response[owner][state][default_values.index(week)] = count
else:
formatted_response[owner] = {"Open": [0] * 6, "Closed": [0] * 6}
formatted_response[owner][state][default_values.index(week)] = count if state is not None else ""
response_result["body"] = formatted_response
The issue is I am checking to make sure that if it the key is None it keeps pulling a KeyError even after checking. The values from state I am getting is Open, Closed and None.
I want it to check if the key is not none and if it is none it populated the dictionary with the dictionary with Open and Closed values.
1