kabeer
(Kabeer)
October 8, 2019, 1:02pm
1
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?
vp109
(Vishal)
October 9, 2019, 4:18am
3
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))
1 Like
kabeer
(Kabeer)
October 9, 2019, 6:15am
5
Thanks @vp109 , your solution worked.