i'm stuck with my simple code, i'm a newbie for coding.. I'm using python and In my list i have bad values that made exceptions (httperror : 404) . I want to ignore this exceptions and continue my loop. But with my code, the print("Http error") loop again and again. I don't know how to pass this exception to loop the entire code again.
while i < len(list_siret):
try :
data = api.siret(list_sirets[i]).get()
str_datajs = json.dumps(data, indent= 4)
a_json = json.loads(str_datajs)
i +=1
print("test1", i ,str_datajs)
except urllib.error.URLError :
print("Http error")
pass
URLError.exceptclause withurllib.error.URLErrorexception. But your code can also raise Exceptions from JSON decodes... IF you want to pass ALL errors, then removeurllib.error.URLError.i += 1is only executed ifapi.siretdoes not raise an exception. If you move that to afinallyclause, you would actually proceed to the next URL (though you would still see "Http error" for each failing URL).