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

Lele Gaifax lele at metapensiero.it
Fri Jul 5 03:06:22 EDT 2013


Νίκος Gr33k <nikos at superhost.gr> writes:

> try:
> 	host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0]
> except Exception as e:
> 	host = "Reverse DNS Failed"
>
> How can the above code not be able to reeverse dns any more and it
> falls back to  the failed string?

The only way to know is actually printing out the exception, either to
stderr, or better using the logging facility, as I suggested.

FYI, your code above is (almost) exactly equivalent to the simpler

    try:
    	host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0]
    except:
    	host = "Reverse DNS Failed"

ciao, lele.
-- 
nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri
real: Emanuele Gaifas | comincerò ad aver paura di chi mi copia.
lele at metapensiero.it  |                 -- Fortunato Depero, 1929.




More information about the Python-list mailing list