This may not be flask related but
with open('db.yaml', 'r') as file:
db = yaml.load(file, Loader=yaml.SafeLoader)
The above works on localhost, but must be edited to get it working on the server :
yaml_file_path = os.path.join(os.path.dirname(__file__), 'db.yaml')
with open(yaml_file_path, 'r') as file:
db = yaml.load(file, Loader=yaml.SafeLoader)