Problem with rest for Rasa running in Docker on GCP

Hey Everyone,

I’m very new to rasa so please excuse potential beginner mistakes. So I have a problem communicating with my fresh installed rasa instance in my GCP VM. I’ve tried multiple things and don’t know where I’m wrong so I’m gonna explain everything I’ve done.

I created a new ubuntu 16.04 LTS VM on GCP matching the minimum requirements for rasa x and installed docker and docker-compose. Then I ran sudo docker run --user root -v $(pwd):/app rasa/rasa init --no-prompt to create the base project and train the first model. I have to do everything with root otherwise I’m having problems with permissions.

I checked all the files and folders in the project directory. Specifically that credentials.yml contains “rest:”.

Then I created docker-compose.yml :

version: '2.0' // Didn't work with 3.0
services:
  rasa:
    image: rasa/rasa
    ports:
      - 5005:5005
    volumes:
      - ./:/app
    command:
      - run

Then I ran sudo docker-compose up -d and checked that everything works with sudo docker container ls output of that is:

CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS                    NAMES
cc1677b364a9        rasa/rasa           "rasa run"          2 minutes ago       Up 7 seconds        0.0.0.0:5005->5005/tcp   rasa_rasa_1

To me that looks good but when I run

curl --location --request POST 'http://localhost:5005/webhooks/rest/webhook?sender=Rasa&message=Hi,%20there%21

I only get:

<h1>Internal Server Error</h1>
<p>
    The server encountered an internal error and cannot complete
    your request.
</p>

And to even get this far took me ages. Previously it just refused the connection. Whenever I try to send the same message from a different network via curl --location --request POST 'http://GcpExternalIP:5005/webhooks/rest/webhook?sender=Rasa&message=Hi,%20there%21 it just times out after a few seconds. I’ve tried Postman on mac, rested (similar to Postman used it before I knew of Postman) and terminal. I’ve tried installing rasa x on the same instance after that and that worked flawlessly. I just followed the tutorial from the rasa masterclass and I could connect to rasa x via firefox but when I compare the running docker containers I couldn’t find a difference in connected networks. But how is it that rasa x is exposed but rasa running on port 5005 isn’t??

Any help is greatly appreciated I don’t know what else to try. Thanks in advance!

@noran did you solve the issue?

Hi @noran @skjainmiah In local host the endpoint is http://localhost:/webhooks/rest/webhook

But things change a lot when you deploy on GCP, Before you use it you have to get an bearer access token by following method:

Your endpoint is :
 http://<your_ip>/api/auth

with Json Body as POST request: 

{
	"username": "your usename, usually its me",
	"password": "your password"
}

It will return something like this:

{
    "access_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJ1c2VybmFtZSI6Im1lIiwiZXhwIjoxNTg2MTE1MDMxLCJ1c2VyIjp7InVzZXJuYW1lIjoibWUiLCJyb2xlcyI6WyJhZG1pbiJdLCJkYXRhIjpudWxsLCJhcGlfdG9rZW4iOiI2MjkzYWU5MDcxMmIyYjEwNzJjNTBmNmFkNTE2YjJlMmUzNTc1ZjE4In0sInNjb3BlcyI6WyJhY3R
---really long access token
pb25QcmVkaWN0aW9uOmNyZWF0ZSIsImFjdGlvblByZWRpY3Rpb246Z2V0IiwiYWN0aW9uczpjcmVhdGUiLCJhY3Rpb25zOmRlbGV0ZSIsImFjdGlvbnM6Z2V0IiwiYWN0aW9uczp1cGRhdGUiLCJhbGxFd
9tWCLbQtPGe8jDfxExLwLdcxvkF7s5DQail8gtt_60mLPAlNRKbWeR3zpJ8RFf_KOAqxXDcg9rrZO-g_hXRng1ePOFOyrOFlQLMp0IN4YwRgHhdbqIlypdw"
}

authentication curl request will be like this:

curl --location --request POST 'http://your_ip/api/auth' \
--header 'Content-Type: application/json' \
--data-raw '{
	"username": "your username",
	"password": "your password"
}'

Now use this bearer token as authentication to chat endpoint:

The endpoints to chat is

http://<your_ip>/api/chat

with body in Json as POST request:

{
      "message" : <your input string here>
}

with bearer token.

Your curl request will be like this:

curl --location --request POST 'http://your ip/api/chat' \
--header 'Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJ1c2VybmFtZSI6Im1lIiwiZXhwIjoxNTg2MTE1MDMxLCJ1c2VyIjp7InVzZXJuYW1lIjoibWUiLCJyb2xlcyI6WyJhZG1pbiJdLCJkYXRhIjpudWxsLCJhcGlfdG9rZW4iOiI2MjkzYWU5MDcxMmIyYjEwNzJjNTBmNmFkNTE2YjJlMmUzNTc1ZjE4In0sInNjb3BlcyI6WyJhY3R
---really long access token
pb25QcmVkaWN0aW9uOmNyZWF0ZSIsImFjdGlvblByZWRpY3Rpb246Z2V0IiwiYWN0aW9uczpjcmVhdGUiLCJhY3Rpb25zOmRlbGV0ZSIsImFjdGlvbnM6Z2V0IiwiYWN0aW9uczp1cGRhdGUiLCJhbGxFd
9tWCLbQtPGe8jDfxExLwLdcxvkF7s5DQail8gtt_60mLPAlNRKbWeR3zpJ8RFf_KOAqxXDcg9rrZO-g_hXRng1ePOFOyrOFlQLMp0IN4YwRgHhdbqIlypdw' \
--header 'Content-Type: application/json' \
--data-raw '{
	"message": "hi"
}'

Refer to this for more documentation HTTP API.

1 Like

@athenasaurav can you help me in deploying my Rasa Chatbot in GCP. As I have no Idea about docker and GCP. My chatbot is ready and I am not getting exact way how to deploy it. I’m searching from 1 month.

Yes sure. Have you watched rasa masterclass. Join me in this tutorial series : https://youtu.be/BIvte_9Jx4E.

I will be building an end to end chatbot tutorial

1 Like

If I get any doubt in deployment can I ask you?

Yes please, happy to help

1 Like

No, unfortunately not. I tried to circumvent it by using sockets instead of http post requests, but I’m not having that much luck with that either.

Thank you very much for that detailed guide, really appreciate it. The first post requests asking for an access token worked flawlessly, but I couldn’t send any messages. I pasted the access token I got from the request into the other post request, but with the same message “hi” I’m just getting empty brackets like so []

Did You added the access token as Bearer token in the authentication window om postman.

Can you post your curl request here?

Okay so I got it to work now. Thanks for the great help. I actually just copied over your curl request. In the end I got it to work with postman, I didn’t know I could put in the access token in the authorisation panel, but this is much cleaner and easier than a curl request…

I think my whole docker-setup had some issues so I did a clean install and added the rest input channel to credential.yml, as that got removed somehow. Then my communication worked. In postman it said status 200, but I still only got the empty square brackets. The issue this time was on rasa’s side. I couldn’t activate a model because I had none, but I also couldn’t train, because it would only say nothing has changed. So I changed a few lines, pushed to git and could train and load the model.

Now everything is working again. Thanks again

@athenasaurav i am facing similar issue in the deployment. Can you elaborate on the provided solution. My actions work fine if not containerized. But when containerized im unable to make HTTP request

Hello @Saraa_m , Happy to help you.

Can you please elobrate your issues and the method which you used? Are you deploying on some VM instance or on localhost? Are you using rasa x or rasa open source for deployment? Also please share your credentials.yml file

@athenasaurav sure. I’m using rasa open source. Im containerizing the package to deploy in kubernetes. There is a rest api call which is failing to execute when i use docker-compose up but works fine if not using docker.

The error message is Internal Server Error. The server encountered an internal error and cannot complete your request. cred.txt (1.1 KB)

@athenasaurav

I’m using rasa open source. Im containerizing the package to deploy in kubernetes. There is a rest api call which is failing to execute when i use docker-compose up but works fine if not using docker. The error message is Internal Server Error. The server encountered an internal error and cannot complete your request

credential.yml cred.txt (1.1 KB) adding my dockerfile as well for your reference. Thanks in advance docker-compose.yaml (589 Bytes)

please help me here!!

My Issue is fixed. My bad I was missing a file in the container and now rectified the same. :slight_smile: Thanks!!!