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.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'causing': 0.04; 'debug': 0.07; 'debugging': 0.07; "subject:' ": 0.07; 'string': 0.09; 'hiding': 0.09; 'output,': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'run,': 0.09; 'subject:position': 0.09; 'variable,': 0.09; 'os.environ': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject: \n ': 0.16; 'subject:start': 0.16; 'variable.': 0.16; 'fix': 0.17; 'wrote:': 0.18; '(not': 0.18; 'do.': 0.18; 'saying': 0.22; 'header:User- Agent:1': 0.23; 'error': 0.23; "aren't": 0.24; 'byte': 0.24; 'unicode': 0.24; 'environment': 0.24; 'skip:" 30': 0.26; 'least': 0.26; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'point': 0.28; 'host': 0.29; 'am,': 0.29; 'characters': 0.30; 'returned': 0.30; 'especially': 0.30; 'lines': 0.31; '"",': 0.31; 'keyerror:': 0.31; 'file': 0.32; 'figure': 0.32; 'running': 0.33; '(most': 0.33; 'problem': 0.35; "can't": 0.35; 'skip:s 30': 0.35; 'something': 0.35; 'but': 0.35; 'there': 0.35; 'earth': 0.36; "i'll": 0.36; 'error.': 0.37; 'wrong': 0.37; 'being': 0.38; 'skip:o 20': 0.38; 'problems': 0.38; 'to:addr:python-list': 0.38; 'rather': 0.38; 'recent': 0.39; 'subject:can': 0.39; 'to:addr:python.org': 0.39; 'enough': 0.39; 'received:org': 0.40; 'dave': 0.60; 'expression': 0.60; 'till': 0.61; 'simple': 0.61; "you're": 0.61; "you'll": 0.62; 'address': 0.63; 'show': 0.63; 'name': 0.63; 'real': 0.63; 'such': 0.63; 'caused': 0.69; '8bit%:92': 0.71; 'greek': 0.84; 'angel': 0.91; 'from.': 0.93; 'yyy': 0.96 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 09:05:33 -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: 49 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1373029556 news.xs4all.nl 15931 [2001:888:2000:d::a6]:40390 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:49981 On 07/05/2013 06:33 AM, Νίκος Gr33k wrote: > Στις 5/7/2013 12:21 μμ, ο/η Dave Angel έγραψε: >> Traceback (most recent call last): >> File "", line 1, in >> File "/usr/local/lib/python3.3/os.py", line 669, in __getitem__ >> value = self._data[self.encodekey(key)] >> KeyError: b'REMOTE_ADDR > > > Wait! > Are you saying that the ip address is being returned as a byte string > which then i have to decode with something like: > > host = socket.gethostbyaddr( os.environ['REMOTE_HOST'].decode('utf-8') )[0] > Don't fix the problem till you understand it. Figure out who is dealing with a byte string here, and where that byte string came from. Adding a decode, especially one that's going to do the same decode as your original error message, is very premature. You're quoting from my error output, and that's caused because I don't have such an environment variable. But you do. So why aren't you in there debugging it? And why on earth are you using the complex expression instead of a refactored one which might be simple enough for you to figure out what's wrong with it. There is definitely something strange going on with that os.environ reference (NOT call). So have you yet succeeded in running the factored lines? If you can't get them to run, at least up to the point that you get that unicode error, then you'll make progress only by guessing. Get to that interactive debug session, and enter the lines till you get an error. Then at least you know which line is causing the error. xxx = os.environ['REMOTE_HOST'] yyy = socket.gethostbyaddr(xxx) host = yyy[0] I'll bet the real problem is you're using some greek characters in the name of the environment variable, rather than "REMOTE_HOST" So everything you show us is laboriously retyped, hiding the real problems underneath. -- DaveA