UnicodeDecodeError issue

Dave Angel davea at davea.name
Sun Sep 1 11:36:24 EDT 2013


On 1/9/2013 10:08, Ferrous Cranus wrote:

   <snip>
> Here is it:
>
>
> errout = open( '/tmp/err.out', 'w' )		# opens and truncates the error 
> output file
> try:
> 	gi = pygeoip.GeoIP('/usr/local/share/GeoIPCity.dat')
> 	city = gi.time_zone_by_addr( os.environ['REMOTE_ADDR'] ) or 
> gi.time_zone_by_addr( os.environ['HTTP_CF_CONNECTING_IP'] )
> 	host = socket.gethostbyaddr( os.environ['REMOTE_ADDR'] )[0] or 
> socket.gethostbyaddr( os.environ['HTTP_CF_CONNECTING_IP'] )[0] or "Proxy 
> Detected"
> except Exception as e:
> 	print( "Xyzzy exception-", repr( sys.exc_info() ), file=errout )
>      errout.flush()
>
> sys.exit(0)
>
> and the output of error file is:
>
>
> nikos at superhost.gr [~]# cat /tmp/err.out
> UnicodeDecodeError('utf-8', b'\xb6\xe3\xed\xf9\xf3\xf4\xef 
> \xfc\xed\xef\xec\xe1 \xf3\xf5\xf3\xf4\xde\xec\xe1\xf4\xef\xf2', 0, 1, 
> 'invalid start byte')
>

Nope.  The label  "Xyzzy exception" is not in that file, so that's not
the file you created in this run.  Further, if that line existed before,
it would have been wiped out by the open with mode "w".

i suggest you add yet another write to that file, immediately after
opening it:

errout = open( '/tmp/err.out', 'w' )		# opens and truncates the error 
print("starting run", file=errorout)
errout.flush()

Until you can reliably examine the same file that was logging your
errors, you're just spinning your wheels.  you might even want to write
the time to the file, so that you can tell whether it was now, or 2 days
ago that the run was made.


-- 
DaveA





More information about the Python-list mailing list