Forums

RASA Chatbot and Flask: requests.exceptions.ConnectionError: HTTPSConnectionPool

Hi, I'm currently trying to implement a chatbot with my frontend

The chatbot server is running and listens to port 5005 on default. The route snippet where I send the payload and receive the response is the following:

        text=form.chat_input.data
        payload = json.dumps({"sender": "Rasa","message": text})
        headers = {'Content-type': 'application/json', 'Accept':     'text/plain'}
        response = requests.request("POST",   url="https://localhost:5005/webhooks/rest/webhook", 
         headers=headers, data=payload)
        response=response.json()
        resp=[]

This works when I am working locally but I get an error in my error log:

requests.exceptions.ConnectionError: HTTPSConnectionPool(host='localhost', port=5005): Max retries exceeded with url: /webhooks/rest/webhook (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7eff9bb9eac0>: Failed to establish a new connection: [Errno 111] Connection refused'))

I'm guessing it has either something to do with the port not being open or me having to alter the url= part of the route code, although the stuff I tried so far (using the IP address I get via console etc.) did not lead to a successful result.

Would be glad if somebody could help me out here what address I have to refer to here to get the webhook working again :)

Thanks

It would not work on PythonAnywhere like that. The only way to have something visible externally is to create a wsgi web app.

I'm sorry I don't fully understand what you mean.

I have a web app deployed through pythonanywhere (current prototype, still very simple: https://www.hsa-gabi.de/) And that's where I need the RASA chatbot to work with, so receive the chat inbox input and send back the responses to the chat window

So I have the rasa server running in the background listening to port 5005 waiting to receive requests through said chat window.

Is why its not working a fundamental issue of how the pythonanywhere infrastructure is built or could I still achieve this with another approach?

"rasa server running in the background listening to port 5005" is not something that anyone could connect to.

your one sentence answers aren't really helping

There is no server running on port 5005 on localhost and there is no possibility that you will be able to get one running on PythonAnywhere. What you are trying to do will not work on PythonAnywhere.

Alright, thank you for elaborating a bit more!

So what I would do then is the following:

1) Keep my website with the chatbot frontend on PythonAnywhere (simple Flask Application) 2) Strip down my Virtual Environment of the RASA dependencies and get rid of it on my pythonanywhere environment 3) Host the RASA Chatbot externally, let's say via Google/AWS or Heroku using Docker 4) Alter my code on my flask website to make the requests to my externally hosted Chatbot API

I assume that it should work fine like that. Else please correct me Sorry to be so persistent.. I'm new to the whole chat bot thing and trying to get this to work

Yes, you can connect to externally hosted service. It should work as you described. Is there any persistent data involved, some database? If so, you need to consider also that. If you want to use PythonAnywhere MySQL or Postgres you will need to setup SSH tunnel.