Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #97107
| Path | csiph.com!usenet.pasdenom.info!news.redatomik.org!newsfeed.xs4all.nl!newsfeed7.news.xs4all.nl!nzpost1.xs4all.net!not-for-mail |
|---|---|
| Return-Path | <cameron@cskk.homeip.net> |
| 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; 'modify': 0.04; 'except:': 0.07; 'exception.': 0.07; 'stops': 0.07; 'creighton': 0.09; 'exception': 0.13; 'wed,': 0.15; '"connection': 0.16; "'connection": 0.16; '...]': 0.16; '12:38,': 0.16; '>in': 0.16; 'advice,': 0.16; 'doesnt': 0.16; 'error"': 0.16; 'from:addr:cs': 0.16; 'from:addr:zip.com.au': 0.16; 'from:name:cameron simpson': 0.16; 'handle,': 0.16; 'handling.': 0.16; 'hangs': 0.16; 'message- id:@cskk.homeip.net': 0.16; 'simpson': 0.16; 'sorts': 0.16; 'subject:handling': 0.16; 'wrote:': 0.16; 'laura': 0.18; "shouldn't": 0.18; 'try:': 0.18; '>>>': 0.20; '2015': 0.20; 'do.': 0.22; 'exceptions': 0.22; 'resumes': 0.22; 'sep': 0.22; 'subject:problem': 0.22; 'cheers,': 0.22; 'trying': 0.22; 'code,': 0.23; 'this:': 0.23; 'header:In-Reply-To:1': 0.24; 'all.': 0.24; 'script': 0.25; 'header:User-Agent:1': 0.26; "doesn't": 0.26; 'rest': 0.26; 'error': 0.27; 'least': 0.27; 'said,': 0.27; '-0700,': 0.29; 'catching': 0.29; 'terminating': 0.29; 'asked': 0.29; 'print': 0.30; 'connection': 0.30; 'code': 0.30; 'usually': 0.33; 'raised': 0.33; 'except': 0.34; 'that,': 0.34; 'ones': 0.35; 'something': 0.35; 'but': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'charset:us-ascii': 0.37; 'things': 0.38; 'mean': 0.38; 'offered': 0.38; 'end': 0.39; 'why': 0.39; 'to:addr:python.org': 0.40; 'where': 0.40; 'your': 0.60; 'press': 0.61; 'suitable': 0.61; 'telling': 0.61; 'above,': 0.63; 'cameron': 0.66; 'received:61': 0.72; '>other': 0.84; 'actions,': 0.84; 'happened.': 0.84; 'absolutely': 0.88 |
| X-Authentication-Info | Submitted using ID cskk@bigpond.com |
| X-Authority-Analysis | v=2.0 cv=CsQ9gwED c=1 sm=1 a=iNENZoeHxGo9zu6/TJL/MA==:17 a=vrnE16BAAAAA:8 a=ZtCCktOnAAAA:8 a=ff-B7xzCdYMA:10 a=9HkKwmWGVn9ZH8KyZLIA:9 a=CjuIK1q_8ugA:10 a=iNENZoeHxGo9zu6/TJL/MA==:117 |
| Date | Fri, 25 Sep 2015 09:25:38 +1000 |
| From | Cameron Simpson <cs@zip.com.au> |
| To | python-list@python.org |
| Subject | Re: ConnectionError handling problem |
| MIME-Version | 1.0 |
| Content-Type | text/plain; charset=us-ascii; format=flowed |
| Content-Disposition | inline |
| In-Reply-To | <201509241038.t8OAcT1Z013215@fido.openend.se> |
| User-Agent | Mutt/1.5.23 (2014-03-12) |
| References | <201509241038.t8OAcT1Z013215@fido.openend.se> |
| 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.157.1443140162.28679.python-list@python.org> (permalink) |
| Lines | 47 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1443140162 news.xs4all.nl 23744 [2001:888:2000:d::a6]:46624 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:97107 |
Show key headers only | View raw
On 24Sep2015 12:38, Laura Creighton <lac@openend.se> wrote:
>In a message of Wed, 23 Sep 2015 19:49:17 -0700, shiva upreti writes:
>>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.
[... snip ...]
Since nobody has offered this advice, let me:
Firstly, as already remarked bare excepts are overkill - they catch all sorts
of things you shouldn't be handling.
That said, if you _don't know_ what exceptions are going to boils out of new
code, this is one way to see them all. However, you are catching _everything_
but _not_ finding out what happened.
Try this:
try:
r=requests.post(url, data=query_args)
except Exception as e:
print "Exception:", e
That will at least _tell_ you what happened. You code is blithely presuming
Connection Error and telling you that, but it is usually a lie.
Once you have characterised what exceptions you get, and which particular ones
to handle, then modify your code to catch _only_ those and perform the specific
suitable actions, and let the rest escape.
Cheers,
Cameron Simpson <cs@zip.com.au>
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
Re: ConnectionError handling problem Cameron Simpson <cs@zip.com.au> - 2015-09-25 09:25 +1000
Re: ConnectionError handling problem shiva upreti <katewinslet626@gmail.com> - 2015-09-24 20:57 -0700
Re: ConnectionError handling problem Cameron Simpson <cs@zip.com.au> - 2015-09-25 14:59 +1000
Re: ConnectionError handling problem shiva upreti <katewinslet626@gmail.com> - 2015-09-24 22:46 -0700
Re: ConnectionError handling problem Cameron Simpson <cs@zip.com.au> - 2015-09-25 17:24 +1000
Re: ConnectionError handling problem shiva upreti <katewinslet626@gmail.com> - 2015-09-29 23:04 -0700
Re: ConnectionError handling problem Cameron Simpson <cs@zip.com.au> - 2015-10-01 07:30 +1000
Re: ConnectionError handling problem Laura Creighton <lac@openend.se> - 2015-09-30 23:56 +0200
csiph-web