Error in HTTP POST requests - RESTfulAPI


I am trying to connect my bot with a chat interface on a website using REST API. Before doing so I started testing the available web server routes. All the GET requests work prefectly fine, but I am getting errors when I try executing POST requests.

Additional Info - I have the bot running on a remote docker container. I used the image rasa/rasa:latest-spacy-en

$curl http://<server-ip>:<port>/webhooks/rest

$curl http://<server-ip>:<port>/
Hello from Rasa: 1.1.4

$curl http://<server-ip>:<port>/webhooks/rest/webhook -d '{"sender":"default","message":"Hello"}'
Error: Failed when parsing body as json

$curl http://<server-ip>:<port>/model/parse -d '{"text":"Hello"}'
{"version":"1.1.4","status":"failure","message":"An unexpected error occurred. Error: Failed when parsing body as json","reason":"ParsingError","details":{},"help":null,"code":500}

And I found this in the container logs

## Server side error message
During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/sanic/", line 917, in handle_request
    response = await response
  File "/usr/local/lib/python3.6/asyncio/", line 110, in __next__
    return self.gen.send(None)
  File "/usr/local/lib/python3.6/site-packages/rasa/core/channels/", line 433, in receive
    sender_id = await self._extract_sender(request)
  File "/usr/local/lib/python3.6/asyncio/", line 110, in __next__
    return self.gen.send(None)
  File "/usr/local/lib/python3.6/site-packages/rasa/core/channels/", line 393, in _extract_sender
    return req.json.get("sender", None)
  File "/usr/local/lib/python3.6/site-packages/sanic/", line 143, in json
  File "/usr/local/lib/python3.6/site-packages/sanic/", line 153, in load_json
    raise InvalidUsage("Failed when parsing body as json")
sanic.exceptions.InvalidUsage: Failed when parsing body as json

Any suggestion on what I would be wrong? or am I missing any configurations?

1 Like

Hey @shreyask92, you can refer this post

Hope this helps you :slight_smile:

@shreyask92 i am facing this same error , did you find a solution ?

Hi @saida

Yes I did. I was using “rasa run -vv --enable-api”. I changed this to “rasa run -m models --enable-api --cors ‘*’ --debug” and it started working.

Give it a try and let me know if its not working.

Continuing the discussion from Error in HTTP POST requests - RESTfulAPI:

Hi ,

I have followed all the steps to run the rasa model provided in this link

But I am unable to fetch the intents and entities while running the CURL . Error: {“version”:“1.1.5”,“status”:“failure”,“message”:“An unexpected error occurred. Error: Failed when parsing body as json”,“reason”:“ParsingError”,“details”:{},“help”:null,“code”:500}

Can somebody help me to solve this issue ?

1 Like

@sravya I am also facing the same issue. Were you able to resolve this?

@aayush3011 Try the solution in post#4. If that step was fine then, just try the below code (change the url as required)

curl localhost:5005/model/parse -d "{\"text\":\"hello\"}"

The problem is with how the body is sent. Just use the backslash to escape the " characters and it will start working.

1 Like

Hi I am also facing this issue :frowning: 45%20PM

Buttons are not working. Please help with proper steps and do I have to add any url in interactivity sections of App ?

hey @dharvi, you can check this thread:

Hey @JiteshGaikwad I’m receiving Slack messages using Python flask and I want display them in a chatbot UI

Which UI are you using and what messages do you want to show?

I’m using your UI and I want messages from slack channel

Ok. So do you want to send the bot messages from slack or something else?

I want to replace rasa with human agent, so I create custom actions to send message to slack channel and I’m using flask for receive messages

I think so we have discussed this in some other post, I haven’t worked yet on slack human agent-handoff yet but will soon do it.

Actually this UI was designed to handle bot response from Rasa but if you want to do something else you need to modify the UI script to handle those responses.

okeey, I’ll try

Thank you @JiteshGaikwad

Thank you so much. This solved my problem.