Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #97068
| From | Laura Creighton <lac@openend.se> |
|---|---|
| Subject | Re: ConnectionError handling problem |
| References | <c56e680b-2e04-4fc6-ba57-5ec64459bce9@googlegroups.com> <mtk1sh$ik6$1@ger.gmane.org> <mailman.39.1442760018.21674.python-list@python.org> <e13ed686-94af-444d-a67b-194fe13b0769@googlegroups.com> |
| Date | 2015-09-24 12:38 +0200 |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.120.1443091118.28679.python-list@python.org> (permalink) |
In a message of Wed, 23 Sep 2015 19:49:17 -0700, shiva upreti writes: >Hi >If my script hangs because of the reasons you mentioned above, why doesnt it catch ConnectionError? >My script stops for a while and when I press CTRL+C, it shows ConnectionError without terminating the process, and the script resumes from where it left off. This is exactly what you asked it to do. :) >> try: >> r=requests.post(url, data=query_args) >> except: >> print "Connection error" >> time.sleep(30) >> continue try to do something until you get an Exception. Since that is a naked except, absolutely any Exception will do. That you print out 'Connection error' doesn't mean that you are only catching exceptions raised by trying to send something to the other end ... any Exception will do. So what happens when you press Control-C? You get a KeyboardInterrupt exception! :) see: https://docs.python.org/2/library/exceptions.html And you are catching it :) And when you catch it you print Connection error and keep on trying. This is why people were telling you that naked try:except: pairs, are rarely what you want. You didn't want to catch control-c but you caught it anyway. Laura
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
ConnectionError handling problem shiva upreti <katewinslet626@gmail.com> - 2015-09-18 23:13 -0700
Re: ConnectionError handling problem Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-09-19 17:18 +0100
Re: ConnectionError handling problem Jon Ribbens <jon+usenet@unequivocal.co.uk> - 2015-09-20 12:45 +0000
Re: ConnectionError handling problem Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-09-20 14:13 +0100
Re: ConnectionError handling problem Jon Ribbens <jon+usenet@unequivocal.co.uk> - 2015-09-20 13:28 +0000
Re: ConnectionError handling problem Chris Angelico <rosuav@gmail.com> - 2015-09-20 23:25 +1000
Re: ConnectionError handling problem Jon Ribbens <jon+usenet@unequivocal.co.uk> - 2015-09-20 13:33 +0000
Re: ConnectionError handling problem Laura Creighton <lac@openend.se> - 2015-09-20 16:40 +0200
Re: ConnectionError handling problem shiva upreti <katewinslet626@gmail.com> - 2015-09-23 19:49 -0700
Re: ConnectionError handling problem Laura Creighton <lac@openend.se> - 2015-09-24 12:38 +0200
Re: ConnectionError handling problem shiva upreti <katewinslet626@gmail.com> - 2015-09-24 20:52 -0700
Re: ConnectionError handling problem shiva upreti <katewinslet626@gmail.com> - 2015-09-24 22:41 -0700
Re: ConnectionError handling problem shiva upreti <katewinslet626@gmail.com> - 2015-09-24 22:42 -0700
csiph-web