Python Forum

Full Version: FTp timeout except
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello
I'm uploading a script file to a server
which casue the server to reboot ( which is what I want )
how do I make the python ignore it? and say it's OK?
If I get not reply in 20 seconds continue ?

Is this enough?
 ftp = FTP(routerIP, timeout=20)
or I need to catch some exception?

this is what I have on the code:
except Exception as e: print('my error') print(e)
and I see I get this on the print out
my error timed out
for me it's not an error
Thanks,
If you don't expect a response why are you waiting 20 seconds instead of something shorter?

You should only capture exceptions you want to handle. The FTP timeout is a socket timeout.
from ftplib import FTP import socket try: ftp = FTP("whatever", timeout=1) ftp.login() except socket.timeout: # I expect a timeout. I want other exceptions to crash and give me a trace pass print("All done")
I thought that the timeout=20 is for that reason
meaning that if no reply after 20 , is good and continue

I will try what you wrote

Thanks,