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

Νίκος Gr33k nikos at superhost.gr
Fri Jul 5 04:49:31 EDT 2013


Στις 5/7/2013 11:35 πμ, ο/η Dave Angel έγραψε:
> On 07/05/2013 04:00 AM, Νίκος Gr33k wrote:
>> Στις 5/7/2013 10:50 πμ, ο/η Dave Angel έγραψε:
>>>
>>> The line started as:
>>>
>>>  >      host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0]
>>>
>>> refactor that to:
>>>         remadd = os.environ('REMOVE_ADDR')
>>>         tuple3 = socket.gethostbyaddr(remadd)
>>>         host = tuple3[0]
>>>
>>> and see which one throws the exception.  Then once you have that,
>>> examine the exact parameters that might be triggering the problem.  In
>>> particular, figure out the exact types and values for remadd and tuple3.
>>>
>>>         print(type(remadd) + " : " + repr(remadd))
>>
>> I'am not sure how iam supposed to write this: i just tried this:
>>
>>
>> try:
>>      remadd = os.environ('REMOVE_ADDR')
>>      tuple3 = socket.gethostbyaddr(remadd)
>>      host = tuple3[0]
>> except:
>>      host = type(remadd) + " : " + repr(remadd)
>>
>>
>> but iam getting an internal server error.
>>
>> I didnt print it as you said but its the same thing host var gets
>> printed later on.
>>
>> Now, why would this give an internal server error?
>>
>
> I have no idea what causes an internal server error.  It's up to you to
> get the output of the expression to some location you can examine.
> Easiest way is to run those 3 lines directly on the server, not in the
> cgi environment.
>
> But if you don't have any debugging tools, then STOP right now and build
> some.  Use logging, or redirect print, or do something that the server
> folks provide as debugging aids.  But just blindly guessing is
> ludicrous.  So also is throwing out clues by using a bare except.
>
> Assigning that string to host makes no sense at all.  And neither does
> putting it in the except clause.  You want to get that string to YOUR
> eyes, not to the server who might get an internal server error.

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:


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



-- 
What is now proved was at first only imagined!



More information about the Python-list mailing list