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


Groups > comp.lang.python > #96874

Re: ConnectionError handling problem

From Mark Lawrence <breamoreboy@yahoo.co.uk>
Subject Re: ConnectionError handling problem
Date 2015-09-20 14:13 +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>
Newsgroups comp.lang.python
Message-ID <mailman.36.1442754847.21674.python-list@python.org> (permalink)

Show all headers | 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