'Slack message not sending on 'else' block

I'm trying to send myself a message on Slack to clarify that the names of the file match the names in the csv cell.

The issue I'm having is that the message does not send for the else block. The output from the print statement is as expected, but I don't know why the Slack message does not send. No errors are provided.

Code and console output below.

def send_slack_message(message):

    webhook = 'https://hooks.slack.com/services/.....'
    message = {
        "text": f"{message}",
        "blocks":[
            {
                "type": "header",
                "text": {
                    "type": "plain_text",
                    "text": f"{message}"
                }
            }]
    }
    return requests.post(webhook, json.dumps(message))


def validate_names(path):

    saved_names = os.listdir(path)

    csv_files = glob.glob(os.path.join(path, "*.csv"))

    cell_names = []
    # loop over the list of csv files
    for f in csv_files:
        # read the csv file
        df = pd.read_csv(f, sep=",", on_bad_lines='skip', header=None)
        myMatrix = df[df.columns[0]].to_numpy()
        cell_names.extend(myMatrix.tolist())

    cell_names_csv = list(map(lambda x: x +'.csv', cell_names))
    joined_lists = dict(zip(saved_names, cell_names_csv))

    failed_list = [key for i, key in enumerate(list(joined_lists.keys())) if key != list(joined_lists.values())[i]]

    if list(joined_lists.keys()) == list(joined_lists.values()):
        print(f"Names are good in: {path}")
        send_slack_message(f"Names are good in: {path}")
    else:
        print(f"These names need fixing: {', '.join(failed_list)} || path: {path}")
        send_slack_message(f"These names need fixing: {', '.join(failed_list)} || path: {path}")

validate_names('C:\\Users\\path\\to\\dir')
validate_names('C:\\Users\\path\\to\\dir')

Console output:

These names need fixing: weekly_report_67483.csv, weekly_report_49385.csv || path: 'C:\Users\path\to\dir' Names are good in: 'C:\Users\path\to\dir'



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source