UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte

Dave Angel davea at davea.name
Fri Jul 5 11:21:33 CEST 2013


On 07/05/2013 04:49 AM, Νίκος Gr33k wrote:
>
      <SNIP>

> 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 "<stdin>", line 1, in <module>
> 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 "<stdin>", line 1, in <module>
   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




More information about the Python-list mailing list