I have the following code that occasionally crashes due to a permissions bug. I am trying to wrap it up in a try / except
statement that will keep trying to launch the driver until successful...
def init_driver():
ffprofile = webdriver.FirefoxProfile("my_profile")
ffprofile.add_extension(extension="myaddon.xpi")
return driver
driver = init_driver()
I have seen examples letting me print a message if an error occurs but how do I get it to keep retrying? Does anybody have an example they can point me at?
Here's a loop that iterates over attempts:
while True:
try:
driver = init_driver()
break
except Foo:
continue
Note that this is not a bare except
clause. Bare except
s are dangerous because they can capture things like NameError
that are so rarely meant to be caught. You should put the specific exception you expect to catch here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With