1 回答

TA貢獻(xiàn)1752條經(jīng)驗(yàn) 獲得超4個(gè)贊
語法應(yīng)該是這樣的:
try:
#this expression was not defined anywhere, hence the NameError
print(leromipsum)
except NameError as error1:
print("meh")
因此,在您的代碼中,我認(rèn)為您應(yīng)該先刪除標(biāo)識(shí):
except:requests.RequestException as error1:
print ("error1:",error1)
并在 except 后刪除冒號(hào):
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)
這個(gè)最小的例子對(duì)我有用。
添加回答
舉報(bào)