Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder5.xlned.com!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.010 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; "subject:' ": 0.07; 'except:': 0.09; 'exception,': 0.09; 'falls': 0.09; 'received:209.85.219': 0.09; 'subject:position': 0.09; 'try:': 0.09; 'fyi,': 0.16; 'handler.': 0.16; 'subject: \n ': 0.16; 'subject:start': 0.16; 'systemexit': 0.16; 'to:name:python list': 0.16; 'exception': 0.16; 'wrote:': 0.18; 'error': 0.23; "aren't": 0.24; 'simpler': 0.24; '>': 0.26; 'equivalent': 0.26; 'logging': 0.26; 'header:In-Reply-To:1': 0.27; 'host': 0.29; 'am,': 0.29; 'message-id:@mail.gmail.com': 0.30; 'code': 0.31; 'equivalent.': 0.31; 'writes:': 0.31; 'received:209.85': 0.35; 'except': 0.35; 'received:google.com': 0.35; 'really': 0.36; 'should': 0.36; 'received:209': 0.37; 'skip:o 20': 0.38; 'skip:& 10': 0.38; 'generic': 0.38; 'to:addr:python-list': 0.38; 'subject:can': 0.39; 'to:addr:python.org': 0.39; 'either': 0.39; 'how': 0.40; 'catch': 0.60; 'back': 0.62; 'more': 0.64; 'jul': 0.74; 'bare': 0.84; 'facility,': 0.91; '2013': 0.98 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:x-gm-message-state; bh=Fb/6ExCHQt6Jk5OutJy0kyQ1rTrByOsJ9AHBMZ4FgOU=; b=mpkblGNtFpvFJO6YnPydbLKsRqKFQQjVceFdO3vRoHSy6lK7EHhR7OL/oFto8ju9Tu ExU1wpmRnFXQlp8VyAW3DxZ3qPyzROzKbrqHRRJb/wLIUPRhZyXUTjl94veSUp/uC5oN lpolVxqJj0L9BZSGrhiskKhgMhkiOxx18hE9NmrWlpVoh7sVCW+5MI9LxR8X1nujcDMy t2vXlxLyk2AOVyKX3nASVx7WTwWOqF8ieRp50djK7Ybqt1sKAGFWO5o85jb0gWcOhOc1 WAF89ikO2HORLYhWrwK3/ll/mI8FHW5ByWM1iNId4moZWWvhOQaaft+tQ6i+JhDb/VGp T0SA== X-Received: by 10.60.98.233 with SMTP id el9mr9712953oeb.46.1373008866913; Fri, 05 Jul 2013 00:21:06 -0700 (PDT) MIME-Version: 1.0 X-Received: by 10.60.98.233 with SMTP id el9mr9712948oeb.46.1373008866846; Fri, 05 Jul 2013 00:21:06 -0700 (PDT) In-Reply-To: <87vc4ph4ep.fsf@nautilus.nautilus> References: <87vc4ph4ep.fsf@nautilus.nautilus> Date: Fri, 5 Jul 2013 00:21:06 -0700 Subject: Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte From: Benjamin Kaplan To: Python List Content-Type: multipart/alternative; boundary=089e0118409ec835f704e0be89b7 X-Gm-Message-State: ALoCoQl88ns9j0ljO+ByXs3Dx3iYmzCr1iwLrEzhWldCIjxDIBPnF07DKgcgd/5RCp9s2JsotRYFmVEuEscrsdnBm5GeFAIWlxuU4c/jedoN687Hq4UupZeJeTOj9n49ZTyrgHs56h7x5lpzSIrhapzO7lBShFLwyQ== X-Junkmail-Whitelist: YES (by domain whitelist at mpv2.tis.cwru.edu) X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 78 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1373009248 news.xs4all.nl 15934 [2001:888:2000:d::a6]:43785 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:49938 --089e0118409ec835f704e0be89b7 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Jul 5, 2013 12:12 AM, "Lele Gaifax" wrote: > > =CE=9D=CE=AF=CE=BA=CE=BF=CF=82 Gr33k writes: > > > try: > > host =3D socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] > > except Exception as e: > > host =3D "Reverse DNS Failed" > > > > How can the above code not be able to reeverse dns any more and it > > falls back to the failed string? > > The only way to know is actually printing out the exception, either to > stderr, or better using the logging facility, as I suggested. > > FYI, your code above is (almost) exactly equivalent to the simpler > > try: > host =3D socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] > except: > host =3D "Reverse DNS Failed" > > ciao, lele. > They aren't equivalent. "except Exception" won't catch KeyboardInterrupt or SystemExit or a few others that you really don't want to catch in a generic error handler. You should almost never have a bare except. --089e0118409ec835f704e0be89b7 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable


On Jul 5, 2013 12:12 AM, "Lele Gaifax" <lele@metapensiero.it> wrote:
>
> =CE=9D=CE=AF=CE=BA=CE=BF=CF=82 Gr33k <nikos@superhost.gr> writes:
>
> > try:
> > =C2=A0 =C2=A0 =C2=A0 host =3D socket.gethostbyaddr( os.environ[&#= 39;REMOTE_ADDR'] )[0]
> > except Exception as e:
> > =C2=A0 =C2=A0 =C2=A0 host =3D "Reverse DNS Failed"
> >
> > How can the above code not be able to reeverse dns any more and i= t
> > falls back to =C2=A0the failed string?
>
> The only way to know is actually printing out the exception, either to=
> stderr, or better using the logging facility, as I suggested.
>
> FYI, your code above is (almost) exactly equivalent to the simpler
>
> =C2=A0 =C2=A0 try:
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 host =3D socket.gethostbyaddr( os.environ[= 'REMOTE_ADDR'] )[0]
> =C2=A0 =C2=A0 except:
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 host =3D "Reverse DNS Failed" >
> ciao, lele.
>

They aren't equivalent. "except Exception" won= 't catch KeyboardInterrupt or SystemExit or a few others that you reall= y don't want to catch in a generic error handler. You should almost nev= er have a bare except.

--089e0118409ec835f704e0be89b7--