用Python发布请求到Slack

时间:2016-07-14 13:44:35

标签: python-3.x post slack

我正在编写一个脚本,用于读取两个CSV文件之间的差异。一旦它被读出,我应该使用WebHook联系一个松弛的页面与比较的结果。我在发送Post方法时遇到了困难。

slack提供的链接产生400的响应 使用/ post或:8080最后得到200,但在松弛页面中没有任何内容出现。

有任何想法或建议吗?

    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()

1 个答案:

答案 0 :(得分:5)

请尝试使用此行:

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