Answer the question
In order to leave comments, you need to log in
How to bypass json and handle exceptions?
There is a json file in which, among other things, there may or may not be a career key (also, in this section, not all fields may be filled out):
{"first_name":"Иван","last_name":"Иванов","bdate":"12.12.2020","site":"xxx.ru","occupation":{"id":297,"name":"МФТИ (Физтех)","type":"university"},"career":[{"city":"Москва","company":"Рога и копыта","from":2006,"position":"продавец","until":2010}],"university_name":"МФТИ (Физтех)","faculty_name":"Факультет проблем физики и энергетики","graduation":1995,"education_status":"Выпускник (магистр)"}
for i in response.json()['response']['items']:
edu = {
"faculty": i.get('faculty_name'),
"chair": i.get('university_name'),
"enter_year": None,
"graduation_year": i.get('graduation')
}
if i.get('career'):
career = []
for y in i['career']:
career.append(
{
"company": i['career'][y]['company'],
"company_web_site": i.get('site'),
# "city": i['career'][y]['city_id'],
"employemnt_year": i['career'][y]['from'],
"quit_year": i['career'][y]['until'],
"position": i['career'][y]['position'],
"desc": None
}
)
else:
career = None
"company": i['career'][y]['company'],
TypeError: list indices must be integers or slices, not dict
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question