Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #59979
| References | <6ad6e381-5f6b-434d-a82b-ff632358839f@googlegroups.com> |
|---|---|
| Date | 2013-11-19 21:54 +1100 |
| Subject | Re: How to catch error messages in ftplib? |
| From | Chris Angelico <rosuav@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.2905.1384858490.18130.python-list@python.org> (permalink) |
On Tue, Nov 19, 2013 at 9:18 PM, JL <lightaiyee@gmail.com> 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?
>
My first suggestion would be to get rid of the try/except block - it's
not really helping you. Just let the exception be displayed. When I
try that, I get a variety of different errors, depending on what sort
of "invalid IP address" was used - if it's malformed
("192.168.1.2.3"), I get a DNS failure, if it's a computer that
doesn't exist but ought to be on my LAN ("192.168.0.2"), I get a
timeout, and if it's one that exists but doesn't have an FTP server
running ("192.168.0.3"), I get a connection refusal. Exactly what I'd
expect to see. Removing the try/except will show what's happening.
ChrisA
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll 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