You have a dictionary, use the dict.get() method to return a default value for missing keys:
image_file = self.request.files.get('image_path') Also, do not use pokemon exception handling. You really don't need to catch them all here; if a key is missing, KeyError is raised, you should catch just that one exception.