Reading that for some file it's right, but for others it's wrong, you can check your path. This is what I use for md5:
def hashsum(path, hex=True, hash_type=hashlib.md5):
hashinst = hash_type()
with open(path, 'rb') as f:
for chunk in iter(lambda: f.read(hashinst.block_size * 128), b''):
hashinst.update(chunk)
return hashinst.hexdigest() if hex else hashinst.digest()
You can use this to compare:
myhash = hashsum(cfile)
sproc = subprocess.Popen(['md5', cfile], stdout=subprocess.PIPE)
syshash = sproc.communicate()[0].split()[0]
print myhash
print syshash
print 'Hash idetntical' if myhash == syshash else 'Hash check fail'
where cfile
is the path to the file. I guess your path is wrong. I'm guessing windows so sys.path[0]
is not the proper way to get the current directory.