I'm trying to determine the data consistency of some files. However, the MD5 keeps coming differently. When I execute md5sum then the hashes are equal:
import hashlib
import os
import sys
def hash_file_content(path):
    try:
        if not os.path.exists(path):
            raise IOError, "File does not exist"
        encode = hashlib.md5(path).hexdigest()
        return encode
    except Exception, e:
        print e
def main():
    hash1 = hash_file_content("./downloads/sample_file_1")
    hash2 = hash_file_content("./samples/sample_file_1")
    print hash1, hash2
if __name__ == "__main__":
   main()
the output is unexpectedly different:
baed6a40f91ee5c44488ecd9a2c6589e 490052e9b1d3994827f4c7859dc127f0
now with md5sum:
md5sum ./samples/sample_file_1
9655c36a5fdf546f142ffc8b1b9b0d93  ./samples/sample_file_1
md5sum ./downloads/sample_file_1 
9655c36a5fdf546f142ffc8b1b9b0d93  ./downloads/sample_file_1
Why is this happening and how can I resolved this?
 
     
    