Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #59976

Re: How to catch error messages in ftplib?

Newsgroups comp.lang.python
Date 2013-11-19 02:20 -0800
References <6ad6e381-5f6b-434d-a82b-ff632358839f@googlegroups.com>
Message-ID <dca243d2-a3dd-49bf-afcc-70335dd8a022@googlegroups.com> (permalink)
Subject Re: How to catch error messages in ftplib?
From JL <lightaiyee@gmail.com>

Show all headers | View raw


I repost the original code segment to make it more complete;

    from ftplib import FTP
    try:
        session = FTP(ftp_server_ip,ftp_user,ftp_password)
        file = open(filename,'rb') # file to send    
        session.storbinary('STOR ' +  filename, file) # send the file
    except Exception, errObj:
        print Exception
        print errObj
    file.close() # close file and FTP
    session.quit()

On Tuesday, November 19, 2013 6:18:07 PM UTC+8, JL wrote:
> I have the following code;
> 
> 
> 
>     try:
> 
>         session = FTP(ftp_server_ip,ftp_user,ftp_password)
> 
>         file = open(filename,'rb') # file to send    
> 
>         session.storbinary('STOR ' +  filename, file) # send the file
> 
>     except Exception, errObj:
> 
>         print Exception
> 
>         print errObj
> 
>     file.close() # close file and FTP
> 
>     session.quit()
> 
> 
> 
> I deliberately placed an invalid ip address for the ftp_server_ip to see whether error messages can be caught. However, no exception was thrown. Can someone more experienced point to me what did I do wrong?
> 
> 
> 
> Thank you.

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

How to catch error messages in ftplib? JL <lightaiyee@gmail.com> - 2013-11-19 02:18 -0800
  Re: How to catch error messages in ftplib? JL <lightaiyee@gmail.com> - 2013-11-19 02:20 -0800
  Re: How to catch error messages in ftplib? Chris Angelico <rosuav@gmail.com> - 2013-11-19 21:54 +1100

csiph-web