我正在 python 应用程序中尝试 try catch 方法。我不确定我犯了什么错误,是缩进问题还是其他问题
这是我的代码。
try:
ivurl = f'{api}/company/{id}/contacts?'
payload: Dict[str, Union[bool, int]] = {'id': True}
response = get_iv_response(url=ivurl, payload=payload)
email_contact_totalresult: int = response.get('totalResults')
email = int(email_contact_totalresult)
payload: Dict[str, Union[bool, int]] = {'name': True}
response = get_iv_response(url=ivurl, payload=payload)
phone_contact_totalresult: int = response.get('totalResults')
phone = int(phone_contact_totalresult)
print ("here")
if email > 0 or phone > 0:
print (f"{id} has contacts")
update_query = f"""update section
set has_contact = true ,
updated = '{cur_date}'
where name = '{id}'
"""
print(update_query)
insert_query = f"""insert into quota(name,age)
values ('{name}',
'{age}')"""
print (insert_query)
cursor.execute(update_query)
cursor.execute(insert_query)
conn.commit()
else :
print (f"{id} doesnot has contacts")
except:requests.RequestException as error1:
print ("error1:",error1)
# except requests.exceptions.HTTPError as error2:
# print ("error1:",error2)
# except requests.exceptions.ConnectionError as error3:
# print ("error3:",error3)
# except requests.exceptions.Timeout as error4:
# print ("error4:",error4)
print ("job done")
print(end_time)
print('Duration: {}'.format(end_time - start_time))
我在“as”无效语法附近遇到错误
本期图片错误: https: //ibb.co/Wn5pnM3
温温酱
相关分类