UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0: invalid start byte
davea at davea.name
Fri Jul 12 17:46:35 CEST 2013
On 07/12/2013 07:56 AM, Ferrous Cranus wrote:
> Στις 12/7/2013 2:47 μμ, ο/η Wayne Werner έγραψε:
>> On Thu, 4 Jul 2013, Νίκος Γκρ33κ wrote:
>>> Στις 4/7/2013 6:10 μμ, ο/η MRAB έγραψε:
>>>> What do you mean "I don't know how to catch the exception with
>>>> OSError"? You've tried "except socket.gaierror" and "except
>>>> socket.herror", well just write "except OSError" instead!
>>> host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )
>>> except OSError:
>>> host = "UnResolved"
>>> produces also an internal server error.
>>> Are you sure is just except OSError ?
>> Have you ensured that 'REMOTE_ADDR' is actually a key in os.environ? I
>> highly recommend using the logging module to help diagnose what the
>> actual exception is.
> Yes it is a key, but the problem as i suspected was cloudflare.
> i had to use os.environ['HTTP_CF_CONNECTING_IP'] that cloudflare passes
> as variable i the cgi enviroment in order to retrieve the visitor's ip.
> gi = pygeoip.GeoIP('/usr/local/share/GeoLiteCity.dat')
> city = gi.time_zone_by_addr( os.environ['HTTP_CF_CONNECTING_IP'] )
> host = socket.gethostbyaddr( os.environ['HTTP_CF_CONNECTING_IP'] )
> except Exception as e:
> host = repr(e)
> Sometimes though iam still receiving the usual
> UnicodeDecodeError('utf-8', b'\xc1\xf0\xef\xf4\xf5
> but only for a few ip addresses, in moste cases it works.
And naturally, you now know how to debug those UnicodeDecodeError
problems. Surely, the code you post here isn't what you actually do,
because when people spend time to give you detailed advice, you actually
read it, and work at understanding it.
More information about the Python-list