我在 Python 中有一段代码,它似乎在概率上导致了一个错误,因为它正在访问一个服务器,有时该服务器有500个内部服务器错误。我想继续尝试,直到我没有得到错误。我的解决办法是:
while True:
try:
#code with possible error
except:
continue
else:
#the rest of the code
break
This seems like a hack to me. Is there a more Pythonic way to do this?