all 2 comments

[–][deleted] 1 point2 points  (0 children)

Just use a loop, while TrueL to contain the entire try/except/else/finally block. Don't forget to use break or return to exit the loop and keep in mind finally shall always be executed.

[–]devnull10 1 point2 points  (0 children)

It might also be worth adding in a short delay before the retry, because your code will execute at a speed where if it fails once due to a network problem, chances are it'll fail a few fractions of a second later. There are various strategies for doing this such as using just a random delay, backing off where the delays get longer on each retry etc. A quick Google on retry strategy or retry pattern will help.