Connecting chatbot to Microsoft SQL Server database

Hi,

I’m using Microsoft SQL Server Management System to retrieve data from a database by querying it through a custom action. My code doesn’t seem to be working. I have never worked with SQL Server before so I can’t understand where the problem is coming from. Here is the code for connection:

(server details removed)

I have imported pyodbc for this. Here is my action server log (it shows that the action was called) -

2019-08-06 15:17:14 INFO     rasa_sdk.executor  - Registered function for 'action_flight_time'.
2019-08-06 15:17:14 INFO     rasa_sdk.executor  - Registered function for 'action_restarted'.
2019-08-06 15:17:14 INFO     rasa_sdk.executor  - Registered function for 'action_slot_reset'.
2019-08-06 15:17:14 INFO     rasa_sdk.executor  - Registered function for 'flight_form'.
2019-08-06 15:17:14 INFO     rasa_sdk.executor  - Registered function for 'aircraft_form'.
2019-08-06 15:17:14 INFO     rasa_sdk.executor  - Registered function for 'airfare_form'.
2019-08-06 15:17:14 INFO     rasa_sdk.endpoint  - Action endpoint is up and running. on ('0.0.0.0', 5055)
127.0.0.1 - - [2019-08-06 15:17:24] "POST /webhook HTTP/1.1" 200 186 2.094049
127.0.0.1 - - [2019-08-06 15:17:56] "POST /webhook HTTP/1.1" 200 186 0.002959

I am testing it through command line right now. It does print 'failed', which means it is trying to execute the try block in the submit function but fails somewhere. The slots required for the query are getting filled before this. Have been stuck here for a while!

edit: I have also tried a slight variation:

for row in cursor:
	dispatcher.utter_message(row.FLIGHT_NUMBER + " " + row.AIRLINE + " " + row.PRICE)

(without [ ]) and no change in problem.

Hi @nikitajain18,

What is the error message on the action server when the try: block is removed?

1 Like

It has been fixed! The error was TypeError: unsupported operand type(s) for +: 'float' and 'str'. I was using the last utter_message incorrectly.

1 Like