I have a python app in which I am creating packages in windows to be used and later compared in a linux python app. I am creating an md5 for a file in windows to be checked later in linux. The problem is that the same code on the same file gives different Md5 hash results in each environment. Below is the method I use to calculate the Md5. (It is the same code on each end, and I am using Python 2.6.5 for both windows/linux environments) When I run this on the same file in different environments, I get md5 hashes that do not match.
def md5_for_file(filePath):
md5 = hashlib.md5()
file = open(filePath)
while True:
data = file.read(8192)
if not data:
break
md5.update(data)
file.close()
return md5.hexdigest()
Any ideas or suggestions are appreciated.
Change open(filePath)
to open(filePath, 'rb')
, where the b
is for binary mode. You're currently opening in text mode, which can cause portability issues.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With