# Accessing RASA NLU only server from python code using API

**URL:** <https://forum.rasa.com/t/accessing-rasa-nlu-only-server-from-python-code-using-api/51126>\
**Category:** Feedback on Rasa Open Source\
**Tags:** community\
**Created:** [February 4, 2022, 9:03am UTC](https://forum.rasa.com/t/accessing-rasa-nlu-only-server-from-python-code-using-api/51126 "2022-02-04T09:03:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sandeeppandey456](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/sandeeppandey456/32/17527_2.png) [@sandeeppandey456](https://forum.rasa.com/u/sandeeppandey456)\
**Post date:** [February 4, 2022, 9:03am UTC](https://forum.rasa.com/t/accessing-rasa-nlu-only-server-from-python-code-using-api/51126/1 "2022-02-04T09:03:13Z")

</div>

I want to use Rasa NLU server only for my custom dialogue management , which is written in a python code. For that i want to post messages to the nlu server and get the intent rankings. I tried -

```auto
text=str(input("Enter the message"))
payload = json.dumps({"sender": "Rasa","message": text})
headers = {'content-type': 'application/json'}
response = requests.request("POST",'http://10.101.1.239:5005/model/parse', json=payload, headers=headers)
response = response.json()
print("response :\n",response)

```

However it throws an error, -

> response : {‘version’: ‘2.8.18’, ‘status’: ‘failure’, ‘message’: ‘An unexpected error occurred. Error: string indices must be integers’, ‘reason’: ‘ParsingError’, ‘details’: {}, ‘help’: None, ‘code’: 500}

But if the payload is -

```auto
payload = {'text':'hi how are you?'}
headers = {'content-type': 'application/json'}
r = requests.post('http://10.101.1.239:5005/model/parse', json=payload, headers=headers)

```

then i get the list of intent rankings properly.

The sender id is necessary as I am trying to manage dialogues externally through my code. Please help

---

<div class="post-metadata">

**Author:** ![E-dC](https://avatars.discourse-cdn.com/v4/letter/e/9fc348/32.png) [@E-dC](https://forum.rasa.com/u/E-dC)\
**Post date:** [February 4, 2022, 2:27pm UTC](https://forum.rasa.com/t/accessing-rasa-nlu-only-server-from-python-code-using-api/51126/2 "2022-02-04T14:27:30Z")

</div>

Hi @sandeeppandey456 ,

The following should work, it looks like the issue was that you used `"message"` in your `payload` instead of `"text"`:

```auto
text = str(input("Enter the message"))
payload = {"sender": "Rasa","text": text})
headers = {'content-type': 'application/json'}
response = requests.post('http://10.101.1.239:5005/model/parse', json=payload, headers=headers)
response = response.json()
print("response :\n",response)

```

That being said, I’m not sure the server will send back the `sender_id` bit. You could try with `message_id`: [Rasa Open Source Documentation](https://rasa.com/docs/rasa/pages/http-api#operation/parseModelMessage)

Alternatively, you could load a NLU model directly in your code: see [Using nlu model with Interpreter.load in Rasa 3.0 - #8 by isgaal](http://forum.rasa.com/t/using-nlu-model-with-interpreter-load-in-rasa-3-0/50460/8)

Hope that helps

---

<div class="post-metadata">

**Author:** ![marktoddy](https://avatars.discourse-cdn.com/v4/letter/m/dfb087/32.png) [@marktoddy](https://forum.rasa.com/u/marktoddy)\
**Post date:** [October 10, 2022, 12:23pm UTC](https://forum.rasa.com/t/accessing-rasa-nlu-only-server-from-python-code-using-api/51126/3 "2022-10-10T12:23:00Z")

</div>

> [@sandeeppandey456](#):
>
> ‘An unexpected error occurred. Error: string indices must be integers’,

TypeError: means that you are trying to perform an operation on a value whose type is not compatible with that operation. An Iterable is a collection of elements that can be accessed sequentially . In Python, iterable objects are indexed using numbers . When you try to access an iterable object using a string or a float as the index, an error will be returned as TypeError: string indices must be integers. This means that when you’re accessing an iterable object like a string or float value, you must do it using an integer value.

For example, str[hello"] and str[2.1] as indexes. As these are not integers, a TypeError exception is raised. This means that when you’re accessing an iterable object like a string or float value, you must do it using an integer value . If you are accessing items from a dictionary , make sure that you are accessing the dictionary itself and not a key in the dictionary.

Python supports slice notation for any sequential data type like lists, strings , tuples, bytes, bytearrays, and ranges. When working with strings and slice notation, it can happen that a TypeError: [string indices must be integers](http://net-informations.com/python/err/indices.htm) is raised, pointing out that the indices must be integers, even if they obviously are.
