elif len(matching_keys) == 0: raise Exception("{} not found".format(key)) should be getkey
should be getkey