with open(tmpfile, 'rb') as inf:
    with open(tmpfile, 'wb') as ouf:
        while True:
            data = inf.read(BLOCKSIZE)
if not data:
    break
converted = data.decode('latin1').encode('utf-8')
ouf.write(converted)
Fastest way to convert file from latin1 to utf-8 in python