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

Dave Angel davea at davea.name
Fri Jul 5 10:35:18 CEST 2013


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.


-- 
DaveA




More information about the Python-list mailing list