1 回答
TA贡献1752条经验 获得超4个赞
语法应该是这样的:
try:
#this expression was not defined anywhere, hence the NameError
print(leromipsum)
except NameError as error1:
print("meh")
因此,在您的代码中,我认为您应该先删除标识:
except:requests.RequestException as error1:
print ("error1:",error1)
并在 except 后删除冒号:
except requests.RequestException as error1:
print ("error1:",error1)
干杯
编辑:
try:
print("this code runs")
raise requests.HTTPError
print("this code is skipped, if an error occurs")
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)
这个最小的例子对我有用。
添加回答
举报