Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!ecngs!feeder2.ecngs.de!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.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'parameters': 0.04; 'class,': 0.07; "subject:' ": 0.07; 'suggestions,': 0.07; 'utf-8': 0.07; 'exception.': 0.09; 'falls': 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; 'throws': 0.09; 'try:': 0.09; 'excerpt': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject: \n ': 0.16; 'subject:start': 0.16; 'suppressing': 0.16; 'exception': 0.16; 'wrote:': 0.18; 'trying': 0.19; 'print': 0.22; 'header:User- Agent:1': 0.23; 'class.': 0.26; 'code:': 0.26; 'values': 0.27; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'host': 0.29; 'am,': 0.29; 'code': 0.31; 'requests': 0.31; 'cgi': 0.31; 'figure': 0.32; 'regular': 0.32; 'running': 0.33; 'noticed': 0.34; 'maybe': 0.34; 'problem': 0.35; 'except': 0.35; 'problem.': 0.35; 'but': 0.35; 'too': 0.37; 'being': 0.38; 'skip:o 20': 0.38; 'to:addr:python-list': 0.38; 'files': 0.38; 'previous': 0.38; 'that,': 0.38; 'environment.': 0.39; 'itself': 0.39; 'subject:can': 0.39; 'to:addr:python.org': 0.39; 'either': 0.39; 'received:org': 0.40; 'how': 0.40; 'catch': 0.60; 'tell': 0.60; "you're": 0.61; 'here:': 0.62; 'back': 0.62; "you've": 0.63; 'url:index': 0.63; 'more': 0.64; 'reverse': 0.68; 'url:page': 0.74; 'as:': 0.81; 'bare': 0.84; 'firing': 0.84; 'url:log': 0.84; 'examine': 0.93 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Dave Angel Subject: Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte Date: Fri, 05 Jul 2013 03:50:52 -0400 References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Gmane-NNTP-Posting-Host: 174.32.174.34 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130510 Thunderbird/17.0.6 In-Reply-To: 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: 58 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1373010669 news.xs4all.nl 15952 [2001:888:2000:d::a6]:36758 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:49943 On 07/05/2013 02:51 AM, Νίκος Gr33k wrote: > > Please help because i just happened to noticed that after having this code: > > try: > host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] > except Exception as e: > host = "Reverse DNS Failed" Don't ever catch a bare Exception class. Make it more specific to the particular problem you're trying to suppress. In particular, your previous problem with the utf-8 decoding will also be caught by the Exception class, so it'll get all lumped together as "Reverse DNS Failed". > > > all requests are being resolves, result to: > > > Reverse DNS Failed as you can see here: > http://superhost.gr/?show=log&page=index.html > > How can the above code not be able to reeverse dns any more and it falls > back to the failed string? > Since you've not made any progress with all the other suggestions, how about if you decompose this line into several, and see just which one is failing? Maybe that'll tell you what's going on. In general, suppressing an exception without knowing why it's firing is a huge mistake. The line started as: > host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] refactor that to: remadd = os.environ('REMOVE_ADDR') tuple3 = socket.gethostbyaddr(remadd) host = tuple3[0] and see which one throws the exception. Then once you have that, examine the exact parameters that might be triggering the problem. In particular, figure out the exact types and values for remadd and tuple3. print(type(remadd) + " : " + repr(remadd)) Of course, print itself won't work too well in a CGI environment. But you must have solved that problem by now, either using log files or running the program excerpt in a regular console. -- DaveA