Encode unicode values before passing through to hashlib

A file with a path containing accented characters caused the `hashlib.sha1()` call to fail as it doesn't expect unicode data. This change encodes the generated string into utf-8 before it gets passed into the sha1 call and thus fixes the bug.