Get error message from FTPLib
Jeff McNeil
jeff at jmcneil.net
Wed Sep 23 14:55:43 EDT 2009
On Sep 23, 1:46 pm, Bakes <ba... at ymail.com> wrote:
> I am using ftplib for a project, using a try/except loop.
>
> I would like to find out the exception, but I am a python newbie and
> do not know how.
>
> How, in a try/except loop would I find the ftplib exception?
For a bit on exception handling in general, check out the section
within the Python tutorial: http://docs.python.org/tutorial/errors.html.
As far as the ftplib module goes, it has an attribute named
'all_errors.' It's a tuple that contains all of the Exception types
that ftplib.FTP methods will throw. You can do something like the
following:
try:
FTP_instance.do_something()
except ftplib.all_errors, e:
handle_an_error(e)
I do something much like that in an NMS-like application I wrote.
--
Thanks,
Jeff
mcjeff.blogspot.com
More information about the Python-list
mailing list