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


Groups > comp.lang.python > #96874

Re: ConnectionError handling problem

Path csiph.com!news.mixmin.net!weretis.net!feeder1.news.weretis.net!feeder.erje.net!1.eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed7.news.xs4all.nl!news.tele.dk!news.tele.dk!small.news.tele.dk!newsgate.cistron.nl!newsgate.news.xs4all.nl!nzpost1.xs4all.net!not-for-mail
Return-Path <python-python-list@m.gmane.org>
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; 'python,': 0.02; 'from:addr:yahoo.co.uk': 0.05; 'except:': 0.07; 'aliases': 0.09; 'oserror': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'python': 0.10; 'exception': 0.13; '"connection': 0.16; '3.3,': 0.16; 'error"': 0.16; 'finer': 0.16; 'hierarchy.': 0.16; 'rationale': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subclasses,': 0.16; 'subject:handling': 0.16; 'wrote:': 0.16; 'try:': 0.18; 'language': 0.19; '>>>': 0.20; 'exceptions': 0.22; 'lawrence': 0.22; 'subject:problem': 0.22; 'absolute': 0.23; 'header:In-Reply-To:1': 0.24; 'header:User-Agent:1': 0.26; 'header:X-Complaints-To:1': 0.26; "skip:' 10": 0.28; 'catching': 0.29; 'pep': 0.29; 'print': 0.30; 'code': 0.30; "i'd": 0.31; 'probably': 0.31; '"the': 0.32; 'language.': 0.32; 'doubt': 0.33; 'except': 0.34; 'handle': 0.34; 'previous': 0.34; 'behind': 0.35; 'ones': 0.35; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'being': 0.37; 'agree': 0.37; 'received:org': 0.37; 'thought': 0.37; 'starting': 0.37; '(with': 0.38; 'minimum': 0.38; 'to:addr:python.org': 0.40; 'mark': 0.40; 'your': 0.60; 'maximum': 0.61; 'charset:windows-1252': 0.62; 'more': 0.63; 'to,': 0.63; 'our': 0.64; 'obvious': 0.76; 'pythonistas,': 0.84
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Mark Lawrence <breamoreboy@yahoo.co.uk>
Subject Re: ConnectionError handling problem
Date Sun, 20 Sep 2015 14:13:21 +0100
References <c56e680b-2e04-4fc6-ba57-5ec64459bce9@googlegroups.com> <mailman.24.1442679607.21674.python-list@python.org> <slrnmvtanf.48q.jon+usenet@frosty.unequivocal.co.uk>
Mime-Version 1.0
Content-Type text/plain; charset=windows-1252; format=flowed
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host 195.147.66.69
User-Agent Mozilla/5.0 (Windows NT 10.0; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.2.0
In-Reply-To <slrnmvtanf.48q.jon+usenet@frosty.unequivocal.co.uk>
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.36.1442754847.21674.python-list@python.org> (permalink)
Lines 31
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1442754847 news.xs4all.nl 23736 [2001:888:2000:d::a6]:39131
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:96874

Show key headers only | View raw


On 20/09/2015 13:45, Jon Ribbens 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.
>

I doubt it, as from the docs "The following exceptions are kept for 
compatibility with previous versions; starting from Python 3.3, they are 
aliases of OSError.".  EnvironmentError is one of those listed.  I'd 
have thought it far more likely that you'd want to catch one or more of 
the OSError subclasses, as finer grained exceptions was part of the 
rationale behind PEP 3151 -- Reworking the OS and IO exception hierarchy.

-- 
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

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