import hashlib mid = 'A10000009296F2'.upper() s = hashlib.sha1(mid.decode('hex')) print s.hexdigest()