How to call callback url from python?

Hi all,

I am trying to call a callback URL from a python function.

Here is the code:

 	rasa_url = "http://localhost:5005/webhooks/callback/webhook"
    wa_data = {
		"sender":"Rasa",
    	"message":"hi"
	}
    r = requests.post(url=rasa_url, data=wa_data)

In the terminal of rasa run, I am getting below error,

 sanic.exceptions.InvalidUsage: Failed when parsing body as json.

I also tried r = requests.post(url=rasa_url, data=json.loads(json.dumps(wa_data)))

How can I solve this?

Hi @kabeer.

Try calling the API with Content-Type header set to application/json. You will also have to pass the data in form of a string and not dict object. Like:

rasa_url = "http://localhost:5005/webhooks/callback/webhook"
wa_data = {
    "sender":"Rasa",
    "message":"hi"
}

headers = {
    "Content-Type": "application/json"
}

r = requests.post(url=rasa_url, headers=headers, data=json.dumps(wa_data))

Thanks @vp109, your solution worked.