# import traceback # def calc(a,b): # res = a/b # return res # # # def main(): # money=input('输入多少钱:') # months=input('还几个月:') # try: # res = calc(int(money),int(months)) # except ZeroDivisionError as e:#try里面的代码出错 走except # traceback.print_exc() # print("还款的月数不能为0",e) # except ValueError as e: # print("输入必须是整数,%s"%e) # except Exception as e: # print('未知错误!') # # else:#没有出错走else # print('每个月还%s'%res) # print('hihihi') # # import pymysql # def main2(): # try: # conn = pymysql.connect() # except Exception as e: # print('数据库连接不了,%s'%e) # else: # cur=conn.cursor() # try: # cur.execute(sql) # except Exception as e: # print('sql语句有错误!%s。sql是"%s"%(e,sql)') # else: # res = cur.fetchall() # return res # finally: # cur.close() # conn.close() import requests def req(): r = requests.get('http://118.24.3.40/api/user/all_stu',headers={'Refere':'http://118.24.3.40/'}) if len(r.json()['stu_info'])<0: pass else: raise Exception('接口无数据')#主动剖出异常 req()