Get error message from FTPLib

B

Bakes

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?
 
J

Jeff McNeil

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

ftplib - Did the whole file get sent? 6
Using a Callback Function - ftplib 4
ftplib limitations? 9
ftplib returns EOFError 0
FTPlib 2
ftplib question 1
Best Way to Handle All Exceptions 19
python3; 0

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top