Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.freenet.ag!news2.euro.net!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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; "subject:' ": 0.07; 'except:': 0.09; 'exception,': 0.09; 'falls': 0.09; 'received:151': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:position': 0.09; 'try:': 0.09; 'emanuele': 0.16; 'fyi,': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject:start': 0.16; 'exception': 0.16; 'header:User-Agent:1': 0.23; 'simpler': 0.24; 'equivalent': 0.26; 'logging': 0.26; 'header:X-Complaints-To:1': 0.27; 'host': 0.29; 'code': 0.31; 'writes:': 0.31; 'except': 0.35; 'skip:o 20': 0.38; 'to:addr:python-list': 0.38; 'subject:can': 0.39; 'to:addr:python.org': 0.39; 'either': 0.39; 'received:org': 0.40; 'how': 0.40; 'che': 0.60; 'back': 0.62; 'more': 0.64; 'quando': 0.84; 'facility,': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Lele Gaifax Subject: Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte Date: Fri, 05 Jul 2013 09:06:22 +0200 Organization: Nautilus Entertainments References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Gmane-NNTP-Posting-Host: 151.62.83.144 User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux) Cancel-Lock: sha1:4eY6rCj5XcjBxsNSAQbMd/S1aqY= 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: 26 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1373007990 news.xs4all.nl 16012 [2001:888:2000:d::a6]:52814 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:49932 Νίκος Gr33k writes: > try: > host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] > except Exception as e: > host = "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 = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] except: host = "Reverse DNS Failed" ciao, lele. -- nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri real: Emanuele Gaifas | comincerò ad aver paura di chi mi copia. lele@metapensiero.it | -- Fortunato Depero, 1929.