Plisken
Plisken

Reputation: 433

Post request in Python to Slack

I'm writing an script that reads in the differences between two CSV files. Once it is read out I am supposed to use a WebHook to contact a slack page with the results of the comparison. I am having difficulty in sending the Post Method.

The link supplied by slack generates a response of 400 with either /post or :8080 at the end you get a 200, but nothing pops up in the slack page.

Any thoughts or suggestions?

    def main():
    csvDiff()
    #print(l)
    post()

def csvDiff():
    f = open("new.csv")
    csv_f = csv.reader(f)
    old=set(pd.read_csv("old.csv", index_col=False, header=None)[0]) #reads the csv, takes only the first column and creates a set out of it.
    new=set(pd.read_csv("new.csv", index_col=False, header=None)[0]) #same here
    diff = new - old
    #Convert the diff set into a list
    diff=list(diff)
    #print(diff)
    #print(newConnections)
    for row in csv_f:
        if row[0] in diff:
            l.append(row)

def makeCsv():
        l = pd.to_csv

def post():
    url = 'whatever'
    payload={"text": "A very important thing has occurred! <https://alert-system.com/alerts/1234|Click here> for details!"}
    r = requests.post(url, data=json.dumps(l).encode('utf8'))
    print(r)

if __name__ == "__main__":
    main()

Upvotes: 2

Views: 2973

Answers (1)

user94559
user94559

Reputation: 60153

Try this line instead:

r = requests.post(url, json=payload)

Upvotes: 6

Related Questions