I would have thought "open(key)" instead of file. Also, you'd need to do, eg
with open(key) as key_file:
  ... key_file.read() ...