I'm writing a program that connects to my website via ftp. If the login authentication fails, I want it to continue on to do something else. But an authentication failure error automatically exits the program. Is there a way to ignore this and continue on?

有帮助吗?

解决方案

You can use Python's Exception Handling:

try:
    do_something()
except Exception, ex:
    print "The process failed because", ex
    do_something_else()

replace do_something() with code you first want to try.. Replace do_somthing_else() code with what you wish to try when do_something() part fails

Reference for Exception Handling

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top