Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed4.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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'encoding': 0.05; 'mrab': 0.05; 'that?': 0.05; 'encoded': 0.07; "subject:' ": 0.07; 'utf-8': 0.07; 'operand': 0.09; 'raises': 0.09; 'subject:position': 0.09; 'try:': 0.09; 'python': 0.11; '(it': 0.16; '(which,': 0.16; '12:50': 0.16; '3.3,': 0.16; 'cease': 0.16; 'codec': 0.16; 'eckhardt': 0.16; 'expecting': 0.16; 'fails.': 0.16; 'oserror': 0.16; 'oserror.': 0.16; 'raised.': 0.16; 'received:forthnet.gr': 0.16; 'sequence.': 0.16; 'subclass': 0.16; 'subject: \n ': 0.16; 'subject:start': 0.16; 'too?': 0.16; 'undo': 0.16; 'alpha': 0.16; 'exception': 0.16; 'followed': 0.16; 'wrote:': 0.18; 'trying': 0.19; '>>>': 0.22; 'import': 0.22; 'previously': 0.22; 'header :User-Agent:1': 0.23; 'error': 0.23; 'byte': 0.24; 'errors.': 0.24; 'instead.': 0.24; 'specify': 0.24; 'script': 0.25; 'right.': 0.26; 'this:': 0.26; 'least': 0.26; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'host': 0.29; 'character': 0.29; "doesn't": 0.30; 'errors': 0.30; 'returned': 0.30; 'said,': 0.30; 'gives': 0.31; '>>>>': 0.31; 'catching': 0.31; 'up.': 0.33; 'could': 0.34; 'problem': 0.35; "can't": 0.35; 'display': 0.35; 'common': 0.35; 'except': 0.35; 'but': 0.35; 'really': 0.36; 'scheme': 0.36; "didn't": 0.36; 'should': 0.36; 'changing': 0.37; 'error.': 0.37; 'clear': 0.37; 'starting': 0.37; 'skip:o 20': 0.38; 'server': 0.38; 'to:addr:python-list': 0.38; 'that,': 0.38; 'subject:can': 0.39; 'to:addr:python.org': 0.39; 'how': 0.40; 'even': 0.60; 'skip:u 10': 0.60; 'catch': 0.60; 'referred': 0.60; 'tell': 0.60; 'skip:a 30': 0.61; 'from:charset:utf-8': 0.61; "you're": 0.61; 'first': 0.61; 'back': 0.62; "you'll": 0.62; "you've": 0.63; 'received:46': 0.66; 'invalid': 0.68; '8bit%:92': 0.71; 'capital': 0.73; 'jul': 0.74; 'back?': 0.84; 'fail.': 0.84; 'fails,': 0.84; 'issues:': 0.84; 'premature': 0.84; 'capture': 0.91; 'from.': 0.93 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=superhost.gr; s=default; h=Content-Transfer-Encoding:Content-Type:In-Reply-To:References:Subject:To:MIME-Version:From:Date:Message-ID; bh=D8vORGYEcGdWBY5z+qnrTHtOJMTsQqV2nfld3vo7Jfc=; b=dZA5GUS10QtIDWzWmduZ9Gmd2lEswtWGKaN5lcCw4PibjCBoT3hVukUAW7SCwMBJSG96HLU3ZWjgknDgDTzXJruciwl/Ny5D77gb5RXiH3xNzyyL16ARETPN8IyV8wifYYxH3D6x6ouzyGGN8+lk0HlEA7qtcR2iLF2OAp+tgoo=; Date: Thu, 04 Jul 2013 16:38:35 +0300 From: =?UTF-8?B?zp3Or866zr/PgiDOk866z4EzM866?= User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64; rv:17.0) Gecko/20130620 Thunderbird/17.0.7 MIME-Version: 1.0 To: python-list@python.org Subject: Re: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte References: In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - nikos.superhost.gr X-AntiAbuse: Original Domain - python.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - superhost.gr X-Get-Message-Sender-Via: nikos.superhost.gr: authenticated_id: nikos@superhost.gr 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: 114 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1372947422 news.xs4all.nl 15915 [2001:888:2000:d::a6]:59667 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:49867 Στις 4/7/2013 4:34 μμ, ο/η MRAB έγραψε: > On 04/07/2013 13:47, Νίκος wrote: >> Στις 4/7/2013 3:07 μμ, ο/η MRAB έγραψε: >>> On 04/07/2013 12:36, Νίκος wrote: >>>> Στις 4/7/2013 2:06 μμ, ο/η MRAB έγραψε: >>>>> On 04/07/2013 11:38, Νίκος wrote: >>>>>> Στις 4/7/2013 12:50 μμ, ο/η Ulrich Eckhardt έγραψε: >>>>>>> Am 04.07.2013 10:37, schrieb Νίκος: >>>>>>>> I just started to have this error without changing nothing >>>>>>> >>>>>>> Well, undo the nothing that you didn't change. ;) >>>>>>> >>>>>>>> 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? >>>>>>> >>>>>>> It's the 0xb6 but it's expecting the starting byte of a UTF-8 >>>>>>> sequence. >>>>>>> Please do some research on UTF-8, that should clear it up. You could >>>>>>> also search for common causes of that error. >>>>>> >>>>>> So you are also suggesting that what gesthostbyaddr() returns is not >>>>>> utf-8 encoded too? >>>>>> >>>>>> What character is 0xb6 anyways? >>>>>> >>>>> Well, it's from a bytestring, so you'll have to specify what encoding >>>>> you're using! (It clearly isn't UTF-8.) >>>>> >>>>> If it's ISO-8859-7 (what you've previously referred to as >>>>> "greek-iso"), >>>>> then: >>>>> >>>>> >>> import unicodedata >>>>> >>> unicodedata.name(b"\xb6".decode("ISO-8859-7")) >>>>> 'GREEK CAPITAL LETTER ALPHA WITH TONOS' >>>>> >>>>> You'll need to find out where that bytestring is coming from. >>>> >>>> Right. >>>> But nowhere in my script(metrites.py) i use an 'Ά' so i really have no >>>> clue where this is coming from. >>>> >>>> And you are right if it was a byte came from an utf-8 encoding scheme >>>> then it would be automatically decoded. >>>> >>>> The only thing i can say for use is that this problem a[[ear only >>>> when i >>>> cloudflare my domain "superhost.gr" >>>> >>>> If i un-cloudlflare it it cease to display errors. >>>> >>>> Can you tell me hpw to write the following properly: >>>> >>>> host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] or >>>> 'UnResolved' >>>> >>>> so even if the function fails "unresolved" to be returned back? >>>> Somehow i need to capture the error. >>>> >>>> Or it dosnt have to do it the or operand will be returned? >>>> >>> If gethostbyaddr fails, it raises socket.gaierror, (which, from Python >>> 3.3 onwards, is a subclass of OSError), so try catching that, setting >>> 'host' to 'UnResolved' if it's raised. >>> >>> Also, try printing out ascii(os.environ['REMOTE_ADDR']). >>> >> >> I have followed your suggestion by trying this: >> >> try: >> host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] >> except socket.gaierror: >> host = "UnResolved" >> >> and then re-cloudlflared "superhost.gr" domain >> >> http://superhost.gr/ gives internal server error. >> > Try catching OSError instead. (As I said, from Python 3.3, > socket.gaierror is a subclass of it.) > At least CloudFlare doesn't give me issues: if i try this: try: host = os.environ['REMOTE_ADDR'][0] except socket.gaierror: host = "UnResolved" then i get no errors and a valid ip back but the above fails. I don't know how to catch the exception with OSError. i know only this two: except socket.gaierror: except socket.herror both fail. -- What is now proved was at first only imagined!