Slack webhook returns invalid_payload when message is a url

13 Views Asked by At

I have:

def send_slack_message(message: str):
    payload = '{"text": "%s"}' % message
    response = requests.post(url,
                             data = payload)
    print(response.text)

def main(message_text: str):
    send_slack_message(message= message_text)

This fails with the error invalid_payload

main(message_text="""Found at \\something.co.uk\\blahblah\\blah""")

Is there documentation regarding what characters are permitted, as \\ and \ is failing in the message, but is required to send a link/windows path.

I looked at Slack Webhook - Getting Invalid_Payload and Slack Webhook - returning invalid_payload, and neither answer my question

This works:

main(message_text = "some text")

Is there a way to format my message so it can send?

1

There are 1 best solutions below

0
frank On

It works when \ is replaced with 4\, ie \\\\

main(message_text="""Found at \\\\somesite.co.uk\\\\blahblah\\\\blah""")