Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Best way to trap errors in ftplib?

Reply
Thread Tools

Best way to trap errors in ftplib?

 
 
Peter A. Schott
Guest
Posts: n/a
 
      01-11-2005
Using ftplib.FTP object for a project we have here to upload/download files. I
know that I can wrap everything in try/except blocks, but I'm having trouble
getting the exact error messages out of the Exceptions.

I'd like to either send an e-mail or log the failure to a database. It would
also be nice to see what the message is and perhaps add some additional logic
for delay/retry or something similar.

Has anyone done any of the above? Willing to share some samples?

Here's a little of my code - maybe you can see what I'm doing/not doing.

def myuploadbinaryfunction(args here):
objFTP = ftplib.FTP(HostName, UserName, Password)
objFTP.cwd(RemotePath)

try:
objFTP.storbinary("STOR " + RemoteFile, file(os.path.join(LocalPath,
LocalFile), "rb"))
SQLLogging.LogFTP(LocalFile, Company, 1)
except Exception, errObj:
SQLLogging.LogFTP(LocalFile, Company, 0)
reportError("Failed to upload " + LocalFile, str(errObj))
print Exception
print errObj



In the above, reportError will send an e-mail to alert. I realize that the
errObj in this case may not have the ability to convert to string, but am not
sure how to get the output otherwise. Not sure how to handle a retry of a
failure, either.

Thank you for your help!

-Peter Schott
 
Reply With Quote
 
 
 
 
Mark McEahern
Guest
Posts: n/a
 
      01-12-2005
Peter A.Schott wrote:

>Using ftplib.FTP object for a project we have here to upload/download files. I
>know that I can wrap everything in try/except blocks, but I'm having trouble
>getting the exact error messages out of the Exceptions.
>
>

Consider using the traceback a la:

try:
[... whatever ...]
except:
import sys, traceback
t, v, tb = sys.exc_info()
# or use StringIO to "print" the traceback to and then log *that*
traceback.print_tb(tb)

// m
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to trap errors on file uploads? SalP ASP .Net 3 05-17-2006 04:34 PM
Trap run time errors in XSLT Rolf Kemper XML 0 10-20-2004 07:07 AM
Trap all errors Andrew Banks ASP .Net 3 04-23-2004 03:39 AM
Errors, errors, errors Mark Goldin ASP .Net 2 01-17-2004 08:05 PM
Trap "connection pool" errors Sean Nolan ASP .Net 1 07-11-2003 02:59 PM



Advertisments