Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #96876
| Path | csiph.com!eternal-september.org!feeder.eternal-september.org!border1.nntp.ams1.giganews.com!nntp.giganews.com!usenetcore.com!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!nzpost1.xs4all.net!not-for-mail |
|---|---|
| Return-Path | <rosuav@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.009 |
| X-Spam-Evidence | '*H*': 0.98; '*S*': 0.00; 'python,': 0.02; 'except:': 0.07; 'cc:addr:python-list': 0.09; '"connection': 0.16; '10:45': 0.16; 'catching),': 0.16; 'error"': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'subject:handling': 0.16; 'wrote:': 0.16; 'stick': 0.18; 'try:': 0.18; '(in': 0.18; '>>>': 0.20; '2015': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'exceptions': 0.22; 'lawrence': 0.22; 'sep': 0.22; 'subject:problem': 0.22; 'absolute': 0.23; 'header:In-Reply-To:1': 0.24; 'message-id:@mail.gmail.com': 0.27; "skip:' 10": 0.28; 'catching': 0.29; 'print': 0.30; 'code': 0.30; 'probably': 0.31; 'maybe': 0.33; 'getting': 0.33; 'except': 0.34; 'handle': 0.34; 'received:google.com': 0.35; 'ones': 0.35; 'should': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'being': 0.37; 'agree': 0.37; '(with': 0.38; 'minimum': 0.38; 'anything': 0.38; 'mark': 0.40; 'your': 0.60; 'maximum': 0.61; 'to,': 0.63; '20,': 0.66; 'worth': 0.67; 'obvious': 0.76; 'chrisa': 0.84; 'thrown,': 0.84; 'to:none': 0.91 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=Hq6/arUGIu+KqUs1PIcpwfEN6jfME2Z93QIVMPMvVVg=; b=FoViFHjc8t1XML5foicB6Y/X4EQL2wUxM5CzeV1cV0pQUW4QlyYJx+CGKPsxT00GI3 Mvop+7o+eGTKVfFbIqtUqmtgCRIRUkoiBHWOH9D/pXKroauP/GNPCA5XqUsUQOERvcUl vYX4EpvCHiDEyLlp/fexeFqLkaJZJRC5namIbCxiD/bLj9BPm9+2SUhszxMJW82wVjYa eE+trSNfF4W2ZZdI9VfFaNxQ1ni1jTqxrIqKDH9281KtpTXqfSpb6Mei80EBEyU6AtyF 0H8LWoiiEZGwGz3vZlFHOog8cerI4aRN67Hz38A74Gv9uRzhHsOwEX7WrB4M1Q9eA7xR rn/A== |
| MIME-Version | 1.0 |
| X-Received | by 10.50.178.145 with SMTP id cy17mr6846125igc.92.1442755558461; Sun, 20 Sep 2015 06:25:58 -0700 (PDT) |
| In-Reply-To | <slrnmvtanf.48q.jon+usenet@frosty.unequivocal.co.uk> |
| References | <c56e680b-2e04-4fc6-ba57-5ec64459bce9@googlegroups.com> <mailman.24.1442679607.21674.python-list@python.org> <slrnmvtanf.48q.jon+usenet@frosty.unequivocal.co.uk> |
| Date | Sun, 20 Sep 2015 23:25:58 +1000 |
| Subject | Re: ConnectionError handling problem |
| From | Chris Angelico <rosuav@gmail.com> |
| Cc | "python-list@python.org" <python-list@python.org> |
| Content-Type | text/plain; charset=UTF-8 |
| 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.38.1442755567.21674.python-list@python.org> (permalink) |
| Lines | 26 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1442755567 news.xs4all.nl 23748 [2001:888:2000:d::a6]:44578 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:96876 |
Show key headers only | View raw
On Sun, Sep 20, 2015 at 10:45 PM, Jon Ribbens <jon+usenet@unequivocal.co.uk> wrote: > On 2015-09-19, Mark Lawrence <breamoreboy@yahoo.co.uk> wrote: >> On 19/09/2015 07:13, shiva upreti wrote: >>> try: >>> r=requests.post(url, data=query_args) >>> except: >>> print "Connection error" >> >> Never use a bare except in Python, always handle the bare minimum number >> of exceptions that you need to, in this case your ConnectionError. > > While I entirely agree with the principle of being specific in what > exceptions you are catching (with the absolute maximum being > 'Exception'), it is often not obvious which ones you need to specify. > The code above probably actually needs to catch EnvironmentError if > it is intended to intercept all network problems. General principle: If you don't know what you should be catching, _catch nothing_. Anything that happens will get printed to the console. Then when you find that something's getting thrown, you check out what its name is, and maybe what its superclasses are (in case there's a broader one worth catching), and only THEN do you stick in a try/except. ChrisA
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