Path: csiph.com!usenet.pasdenom.info!gegeweb.org!newsfeed.kamp.net!newsfeed.kamp.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.005 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'error:': 0.07; "subject:' ": 0.07; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:position': 0.09; 'python': 0.11; 'addr': 0.16; 'behave': 0.16; 'blindly': 0.16; 'brackets': 0.16; 'callable': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject: \n ': 0.16; 'subject:start': 0.16; 'typeerror:': 0.16; 'variable.': 0.16; 'wrote:': 0.18; 'trying': 0.19; 'pointed': 0.19; 'machine': 0.22; '>>>': 0.22; 'import': 0.22; 'header:User- Agent:1': 0.23; 'copied': 0.24; 'parse': 0.24; "shouldn't": 0.24; 'earlier': 0.24; 'environment': 0.24; 'skip:" 30': 0.26; 'header:X -Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'idea': 0.28; 'function': 0.29; 'rest': 0.29; 'am,': 0.29; 'code': 0.31; '"",': 0.31; 'accidentally': 0.31; 'cgi': 0.31; 'keyerror:': 0.31; 'post.': 0.31; 'file': 0.32; 'linux': 0.33; 'running': 0.33; '(most': 0.33; 'bugs': 0.33; 'plain': 0.33; 'could': 0.34; "can't": 0.35; 'skip:s 30': 0.35; 'something': 0.35; 'but': 0.35; 'there': 0.35; 'sequence': 0.36; 'two': 0.37; 'easily': 0.37; 'skip:o 20': 0.38; 'problems': 0.38; 'hat': 0.38; 'to:addr:python- list': 0.38; 'recent': 0.39; 'does': 0.39; 'subject:can': 0.39; 'to:addr:python.org': 0.39; 'changed': 0.39; 'received:org': 0.40; 'how': 0.40; 'skip:u 10': 0.60; 'such': 0.63; 'our': 0.64; 'more': 0.64; 'here': 0.66; 'square': 0.74; 'faithfully': 0.84; 'much,': 0.84; 'pasting': 0.84; 'presumably': 0.84; '2013,': 0.91; 'mistake': 0.91 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 05:21: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: 57 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1373016111 news.xs4all.nl 15959 [2001:888:2000:d::a6]:52407 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:49955 On 07/05/2013 04:49 AM, Νίκος Gr33k wrote: > > I don't think running it via 'cli' would help much, since its a > cgi-script and ip addr function have no meaning calling them in plain > our of a cgi environment but here it is: > No idea how to parse "have no meaning calling them in plain our of a cgi environment" > > Python 3.3.2 (default, Jun 3 2013, 16:18:05) > [GCC 4.4.7 20120313 (Red Hat 4.4.7-3)] on linux > Type "help", "copyright", "credits" or "license" for more information. > >>> import os > >>> remadd = os.environ('REMOVE_ADDR') > Traceback (most recent call last): > File "", line 1, in > TypeError: '_Environ' object is not callable > But there were two problems with the code you faithfully copied from my earlier post. One was already pointed out by feedthetroll, that I accidentally changed REMOTE_ADDR to REMOVE_ADDR. The other one is perhaps more subtle; I replaced square brackets with parentheses. So try again with: >>> import os >>> remadd = os.environ['REMOTE_ADDR'] I get an error: 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' but presumably your machine actually has such an environment variable. Isn't that mistake something you could easily have caught? Or were you just blindly pasting my bugs without understanding what I was trying to do with refactoring? Anyway, I can't see any reason why the rest of the sequence shouldn't behave identically from a terminal as it does in CGI. -- DaveA