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


Groups > comp.lang.python > #97068

Re: ConnectionError handling problem

Path csiph.com!eternal-september.org!feeder.eternal-september.org!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!nzpost1.xs4all.net!not-for-mail
Return-Path <lac@openend.se>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'anyway.': 0.04; 'except:': 0.07; 'exception.': 0.07; 'stops': 0.07; 'received:openend.se': 0.09; 'received:theraft.openend.se': 0.09; 'exception': 0.13; 'wed,': 0.15; '"connection': 0.16; "'connection": 0.16; 'control-c': 0.16; 'doesnt': 0.16; 'error"': 0.16; 'from:addr:lac': 0.16; 'from:addr:openend.se': 0.16; 'from:name:laura creighton': 0.16; 'hangs': 0.16; 'message- id:@fido.openend.se': 0.16; 'pairs,': 0.16; 'received:fido': 0.16; 'received:fido.openend.se': 0.16; 'subject:handling': 0.16; 'laura': 0.18; 'try:': 0.18; '2015': 0.20; 'do.': 0.22; 'exceptions': 0.22; 'resumes': 0.22; 'see:': 0.22; 'sep': 0.22; 'subject:problem': 0.22; 'trying': 0.22; 'script': 0.25; "doesn't": 0.26; 'error': 0.27; '-0700,': 0.29; 'catching': 0.29; 'received:se': 0.29; 'terminating': 0.29; 'asked': 0.29; 'print': 0.30; 'connection': 0.30; 'url:python': 0.33; 'raised': 0.33; 'something': 0.35; 'but': 0.36; 'url:org': 0.36; 'url:library': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'charset :us-ascii': 0.37; 'mean': 0.38; 'end': 0.39; 'why': 0.39; "didn't": 0.39; 'to:addr:python.org': 0.40; 'where': 0.40; 'press': 0.61; 'header:Message-Id:1': 0.61; 'telling': 0.61; 'above,': 0.63; '>if': 0.84; 'header:In-reply-to:1': 0.84; 'absolutely': 0.88
To python-list@python.org
From Laura Creighton <lac@openend.se>
Subject Re: ConnectionError handling problem
In-reply-to <e13ed686-94af-444d-a67b-194fe13b0769@googlegroups.com>
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>
Comments In-reply-to shiva upreti <katewinslet626@gmail.com> message dated "Wed, 23 Sep 2015 19:49:17 -0700."
MIME-Version 1.0
Content-Type text/plain; charset="us-ascii"
Content-ID <13213.1443091109.1@fido>
Content-Transfer-Encoding quoted-printable
Date Thu, 24 Sep 2015 12:38:29 +0200
X-Greylist Sender IP whitelisted, not delayed by milter-greylist-4.3.9 (theraft.openend.se [82.96.5.2]); Thu, 24 Sep 2015 12:38:31 +0200 (CEST)
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.20+
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.120.1443091118.28679.python-list@python.org> (permalink)
Lines 39
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1443091118 news.xs4all.nl 23830 [2001:888:2000:d::a6]:43204
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:97068

Show key headers only | View raw


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 | NextPrevious in thread | Next in thread | Find similar | Unroll thread


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