wired md5 hashing problem
Paul Rubin
http
Sun Mar 26 15:30:22 EST 2006
Matthias Güntert <MatzeGuentert at gmx.de> writes:
> i am in the process of writing a python script to backup my data. Now I
> would like to implement md5/sha1 hashes.
Try editing as follows: change
> f = open(fname, "rb")
> while 1:
> block = f.read(1024*1024)
> if not block:
> break
> # generate the hash
> m.update(block)
> f.close()
to:
f = open(fname, "rb")
nbytes = 0
while 1:
block = f.read(1024*1024)
nbytes += len(block)
if not block:
break
# generate the hash
m.update(block)
f.close()
print '%d bytes processed'
As Adam DePrince noticed, the md5 checksum you generated was that of
an empty file. So the above should tell you whether you're actually
processing any input; if you don't get the expected number of bytes,
debug from there.
More information about the Python-list
mailing list