ftplib errors/exceptions

Matthew Little matthewlittle2006 at gmail.com
Sun Jul 30 18:15:39 EDT 2006


I'm new to Python and I am writing a simple FTP client.  I am having trouble
handling errors like connection refused, invalid username or password, and
the like.  I can use a try exception block like this

try:
  ftp=FTP('some_server')
  ftp.login()
  # more lines
except:
  print "An error has occured.\n"

This works fine to supress the errors, but I would like to be able to narrow
the errors down so that I can print 'invalid username or password' or
'connection refused' rather than simply 'An error has occured'.  How would I
go about narrowing down which errors occur?

Thanks in advance
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20060730/a39abbdf/attachment.html>


More information about the Python-list mailing list