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

Νίκος nikos.gr33k at gmail.com
Sun Sep 29 03:53:36 EDT 2013


Στις 29/9/2013 10:49 πμ, ο/η Νίκος έγραψε:
> Hello although my code is correct just today i saw this in the error_log
>
> [Sun Sep 29 07:44:43 2013] [error] [client 173.245.49.126] Traceback
> (most recent call last):
> [Sun Sep 29 07:44:43 2013] [error] [client 173.245.49.126]   File
> "/home/nikos/public_html/cgi-bin/metrites.py", line 30, in <module>
> [Sun Sep 29 07:44:43 2013] [error] [client 173.245.49.126]     host =
> socket.gethostbyaddr( ipval ) [0]
> [Sun Sep 29 07:44:43 2013] [error] [client 173.245.49.126]
> UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb6 in position 0:
> invalid start byte
> [Sun Sep 29 07:44:43 2013] [error] [client 173.245.49.126] Premature end
> of script headers: metrites.py
>
>
> Which should never had happened since i use the following code:
>
>
> ipval = ( os.environ.get('HTTP_CF_CONNECTING_IP') or
> os.environ.get('REMOTE_ADDR', "Cannot Resolve") )
> city = "Άγνωστη Πόλη"
> host = "Άγνωστη Προέλευση"
> try:
>      gi = pygeoip.GeoIP('/usr/local/share/GeoIPCity.dat')
>      city = gi.time_zone_by_addr( ipval )
>      host = socket.gethostbyaddr( ipval ) [0]
> except socket.gaierror as e:
>      print( "metrites.py => (%s): " % lastvisit, repr( sys.exc_info() ),
> file=open('/tmp/err.out', 'w') )
>
> So vene if somethign might have gone wrong with the 'host' assignment,
> 'host' should have defaulted to "Άγνωστη Προέλευση"
>
> why the utf-8 error?

Since this is not a socket.gaierror it wants:

except Exception as e: ?

i just tried it and now it works.

but then agian why the

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

when it comes to dtermine the 'host' ?



More information about the Python-list mailing list