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


Groups > comp.lang.python > #43194

Re: newbie question about confusing exception handling in urllib

Path csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder2.hal-mli.net!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!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.004
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'handler': 0.05; 'callback': 0.09; 'exception,': 0.09; 'exit': 0.09; 'http': 0.09; 'python:': 0.09; 'seemed': 0.09; 'worked.': 0.09; 'subject:question': 0.10; 'brilliant': 0.16; 'concern,': 0.16; 'dark.': 0.16; 'exceptions,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'message;': 0.16; 'scare': 0.16; 'subject:exception': 0.16; 'subject:handling': 0.16; 'unexpected': 0.16; 'exception': 0.16; 'all.': 0.16; 'language': 0.16; 'fix': 0.17; 'wrote:': 0.18; 'users.': 0.18; 'wed,': 0.18; 'trying': 0.19; 'properly': 0.19; 'server,': 0.19; 'fit': 0.20; 'thanks.': 0.20; 'error': 0.23; 'browsers': 0.24; 'instance,': 0.24; 'server.': 0.24; 'logging': 0.26; 'somewhere': 0.26; 'header:In- Reply-To:1': 0.27; 'function': 0.29; 'am,': 0.29; 'reporting': 0.29; 'mode': 0.30; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; '(which': 0.31; 'code': 0.31; 'block,': 0.31; "d'aprano": 0.31; 'exceptions': 0.31; 'steven': 0.31; 'file': 0.32; 'probably': 0.32; 'running': 0.33; 'received:209.85': 0.35; 'except': 0.35; 'received:209.85.220': 0.35; 'case,': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'acceptable': 0.36; 'crazy': 0.36; 'should': 0.36; 'behind': 0.37; 'received:209': 0.37; 'sometimes': 0.38; 'to:addr:python-list': 0.38; 'rather': 0.38; 'to:addr:python.org': 0.39; 'days': 0.60; 'catch': 0.60; 'problems.': 0.60; 'tell': 0.60; 'full': 0.61; 'matter': 0.61; 'simply': 0.61; 'simple': 0.61; 'skip:n 10': 0.64; 'our': 0.64; 'taking': 0.65; 'details': 0.65; 'saw': 0.77; 'bare': 0.84; 'everything.': 0.84; 'leak': 0.84; 'short,': 0.84; 'story,': 0.91; '2013': 0.98
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:content-type; bh=Etu1nCJ/O1f445MrRT/rn+PxWx9lhOyGuoxlGoNjtfo=; b=MZ65pjqgT4Qm0RPVPFbINpnYlJMESN2f3X4tA1j5pAXuabHu7JY9Z0+BOBisTaa8rL b9gDx4daOqpOzpSPH4nQWWX4Wu29RI0P2J/tTgkOAeyTDQZcX/bQV9mudL12jYtMEmCI Y7sSZ5uVf99FvJuMdmceMvhTP8bUG21HPaCCfLzeW32PvJvpCrUsVhw74D52ER/UFP38 TMsazk3/OrtusKY6DKqdeG4xTU5rmZ6FfMV3oB465IrWF5fkPxgxST1PTSFnYFbQrTcH U/eWCLFKZw+DstcIe2erAKREMvbkyjXhUK2V9Kv/gWhMMucjG5uS2KE4Rqahw6Ea6eEG wY8w==
MIME-Version 1.0
X-Received by 10.220.109.145 with SMTP id j17mr19687939vcp.34.1365524607789; Tue, 09 Apr 2013 09:23:27 -0700 (PDT)
In-Reply-To <51642e32$0$30003$c3e8da3$5496439d@news.astraweb.com>
References <1ae3261b-078d-4362-abff-ea4471addd6a@googlegroups.com> <c395da30-c593-4aeb-960e-69bf98c31880@googlegroups.com> <51642e32$0$30003$c3e8da3$5496439d@news.astraweb.com>
Date Wed, 10 Apr 2013 02:23:27 +1000
Subject Re: newbie question about confusing exception handling in urllib
From Chris Angelico <rosuav@gmail.com>
To python-list@python.org
Content-Type text/plain; charset=ISO-8859-1
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://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 <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.362.1365524611.3114.python-list@python.org> (permalink)
Lines 32
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1365524611 news.xs4all.nl 2612 [2001:888:2000:d::a6]:52805
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:43194

Show key headers only | View raw


On Wed, Apr 10, 2013 at 1:05 AM, Steven D'Aprano
<steve+comp.lang.python@pearwood.info> wrote:
> One exception to this rule (no pun intended) is that sometimes you want
> to hide the details of unexpected tracebacks from your users. In that
> case, it may be acceptable to wrap your application's main function in a
> try block, catch any unexpected exceptions, log the exception, and then
> quietly exit with a short, non-threatening error message that won't scare
> the civilians

This is important to some types of security concern, too; for
instance, if I'm running a web server, I probably don't want to leak
details of exceptions and tracebacks to a potential attacker. Same
again: catch the exception, log it, return simple error message;
additionally, you can return that message as an HTTP response rather
than simply bombing the web server. But again, a bare except should
almost always be logging its exceptions.

True story, though not in Python: After taking over the code of an
ex-coworker, I was trying to fix some crazy problems. Everything I did
seemed to kinda-work, but nothing properly worked. Trying to clean up
the code to comply with "use strict" mode (which will tell you what
language this is, and it isn't Perl) was a matter of blundering about
in the dark. Turned out there was an event handler somewhere that
buried the *entire file full of code* behind a callback that caught
and suppressed everything. Gee, thanks. Web browsers these days are
pretty good at reporting exceptions - we were mainly using Chrome's
inbuilt Firebug-equivalent - but our brilliant coworker saw fit to
hide them all.

Exceptions are a huge boon.

ChrisA

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

newbie question about confusing exception handling in urllib cabbar@gmail.com - 2013-04-09 04:41 -0700
  Re: newbie question about confusing exception handling in urllib Peter Otten <__peter__@web.de> - 2013-04-09 14:19 +0200
  Re: newbie question about confusing exception handling in urllib cabbar@gmail.com - 2013-04-09 06:19 -0700
    Re: newbie question about confusing exception handling in urllib Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-04-09 15:05 +0000
      Re: newbie question about confusing exception handling in urllib Chris Angelico <rosuav@gmail.com> - 2013-04-10 02:23 +1000
      RE: newbie question about confusing exception handling in urllib "Prasad, Ramit" <ramit.prasad@jpmorgan.com> - 2013-04-12 21:29 +0000
  Re: newbie question about confusing exception handling in urllib Terry Jan Reedy <tjreedy@udel.edu> - 2013-04-09 10:19 -0400
  Re: newbie question about confusing exception handling in urllib Ian Kelly <ian.g.kelly@gmail.com> - 2013-04-09 13:11 -0600

csiph-web