Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed2.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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'string.': 0.05; 'that?': 0.05; 'encoded': 0.07; 'returned.': 0.07; "subject:' ": 0.07; 'utf-8': 0.07; 'string': 0.09; 'assuming': 0.09; 'dns,': 0.09; 'exception,': 0.09; 'exception.': 0.09; 'executed': 0.09; 'properly.': 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; 'python': 0.11; '12:59': 0.16; 'codec': 0.16; 'hostname': 0.16; 'pause': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject: \n ': 0.16; 'subject:start': 0.16; 'thread,': 0.16; 'unicode,': 0.16; 'exception': 0.16; 'wrote:': 0.18; 'do.': 0.18; 'trying': 0.19; 'help.': 0.21; '>>>': 0.22; 'header:User-Agent:1': 0.23; 'error': 0.23; 'byte': 0.24; 'specify': 0.24; '(or': 0.24; 'environment': 0.24; 'question': 0.24; 'source': 0.25; 'script': 0.25; 'skip:" 40': 0.26; 'least': 0.26; 'certain': 0.27; 'header:X -Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'idea': 0.28; 'appear': 0.29; 'host': 0.29; 'am,': 0.29; 'character': 0.29; "doesn't": 0.30; "i'm": 0.30; 'gives': 0.31; 'loads': 0.31; 'file': 0.32; '(most': 0.33; 'candidate': 0.34; 'could': 0.34; "can't": 0.35; 'display': 0.35; 'something': 0.35; 'but': 0.35; 'there': 0.35; 'version': 0.36; 'really': 0.36; 'returning': 0.36; 'shows': 0.36; 'should': 0.36; 'changing': 0.37; 'error.': 0.37; 'wrong': 0.37; 'starting': 0.37; 'skip:o 20': 0.38; 'somebody': 0.38; 'to:addr:python-list': 0.38; 'track': 0.38; 'anything': 0.39; 'recent': 0.39; 'does': 0.39; 'subject:can': 0.39; 'to:addr:python.org': 0.39; 'address.': 0.39; 'received:org': 0.40; 'skip:u 10': 0.60; 'dave': 0.60; 'most': 0.60; 'tell': 0.60; 'new': 0.61; 'first': 0.61; 'invalid': 0.68; 'legal': 0.71; '8bit%:92': 0.71; 'jul': 0.74; '2.7.': 0.84; 'premature': 0.84; 'angel': 0.91; 'was:': 0.91; 'from.': 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: Thu, 04 Jul 2013 06:29:25 -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: 75 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1372933781 news.xs4all.nl 15933 [2001:888:2000:d::a6]:51125 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:49836 On 07/04/2013 06:03 AM, Νίκος wrote: > Στις 4/7/2013 12:59 μμ, ο/η Dave Angel έγραψε: >> On 07/04/2013 04:37 AM, Νίκος wrote: >>> I just started to have this error without changing nothing >>> >>> in my index.html(template) and metrites.py(which ipen the template) >>> >>> [Thu Jul 04 11:35:14 2013] [error] [client 108.162.229.97] Original >>> exception was: [Thu Jul 04 11:35:14 2013] [error] [client >>> 108.162.229.97] Traceback (most recent call last): [Thu Jul 04 >>> 11:35:14 2013] [error] [client 108.162.229.97] File >>> "/home/nikos/public_html/cgi-bin/metrites.py", line 19, in >>> [Thu Jul 04 11:35:14 2013] [error] [client 108.162.229.97] host = >>> socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] or >>> 'UnResolved' [Thu Jul 04 11:35:14 2013] [error] [client >>> 108.162.229.97] UnicodeDecodeError: 'utf-8' codec can't decode byte >>> 0xb6 in position 0: invalid start byte [Thu Jul 04 11:35:14 2013] >>> [error] [client 108.162.229.97] Premature end of script headers: >>> metrites.py >>> >>> >>> Why cant it decode the starting byte? what starting byte is that? >> >> The error message means that somebody is trying to decode a byte string >> into Unicode, and using the utf-8 codec for it. Only certain sequences >> are legal in utf-8, and the first byte of a character may not be 0xb6. >> So it gives an error. The question is where does this string come from. >> >> >> Well, the message shows the source line from metrites.py: >> >> host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] or >> 'UnResolved' >> >> So the most likely candidate is the string in the environment named >> "REMOTE_ADDR" Can you display that string? it should look like >> >> "11.24.32.4" >> >> or some other valid IP address. >> >> >> I'm assuming Python 2.7. You should specify the python version when >> starting a new thread, as we (or at least I) cannot keep track of what >> version everyone's running. > > Ima using Python v3.3.2 Dave > > The host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] or > 'UnResolved' should not have give an error since i explicityl tell it > that if it cannot resolve dns the ip to hostname to set it as "unresolved" That's not true. The 'or' doesn't get executed until after the gethostbyaddr() call has returned. So if something's wrong with that call, and it throws an exception, the 'or "unresolved"' won't help. I don't know that this is the problem, and I'm not all familiar with these api's. But I cannot see anything else that could go wrong there to give that particular exception. Unless the hostname it's going to return is a byte string. > > The error appear ONLY when i CloudFlare superhost.gr > > If i pause tthe domain form CloudFlare then my website loads properly. > > I don't really know what CloudFlare is, and have no idea what 'pausing the form' will do. But since it has something to do with dns, perhaps it's returning an invalid host name, one that isn't encoded in utf-8. -- DaveA