# CORS parameter at NLU API

**URL:** <https://forum.rasa.com/t/cors-parameter-at-nlu-api/3185>\
**Category:** Rasa Open Source\
**Created:** [December 1, 2018, 8:08am UTC](https://forum.rasa.com/t/cors-parameter-at-nlu-api/3185 "2018-12-01T08:08:56Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![marcis](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/marcis/32/962_2.png) [@marcis](https://forum.rasa.com/u/marcis)\
**Post date:** [December 1, 2018, 8:08am UTC](https://forum.rasa.com/t/cors-parameter-at-nlu-api/3185/1 "2018-12-01T08:08:56Z")

</div>

What’s the supposed format for the value of --cors option?

I tried the domain name and also “\*”, with an w/o square brackets but didn’t get to send a successful POST request.

My best option now is " --cors ‘\*’ ". I can send a GET /status with that config but the POST request returns a 500 error with this info at server log:

```
     Traceback (most recent call last):
	  File "/home/marcis/.local/lib/python3.6/site-packages/rasa_nlu/server.py", line 142, in decorated
	    return f(*args, **kwargs)
	  File "/home/marcis/.local/lib/python3.6/site-packages/rasa_nlu/server.py", line 125, in decorated
	    return f(*args, **kwargs)
	  File "/home/marcis/.local/lib/python3.6/site-packages/twisted/internet/defer.py", line 1613, in unwindGenerator
	    return _cancellableInlineCallbacks(gen)
	  File "/home/marcis/.local/lib/python3.6/site-packages/twisted/internet/defer.py", line 1529, in _cancellableInlineCallbacks
	    _inlineCallbacks(None, g, status)
	--- <exception caught here> ---
	  File "/home/marcis/.local/lib/python3.6/site-packages/twisted/internet/defer.py", line 1418, in _inlineCallbacks
	    result = g.send(result)
	  File "/home/marcis/.local/lib/python3.6/site-packages/rasa_nlu/server.py", line 229, in parse
	    request.content.read().decode('utf-8', 'strict'))
	  File "/home/marcis/.local/lib/python3.6/site-packages/simplejson/ __init__.py", line 518, in loads
	    return _default_decoder.decode(s)
	  File "/home/marcis/.local/lib/python3.6/site-packages/simplejson/decoder.py", line 370, in decode
	    obj, end = self.raw_decode(s)
	  File "/home/marcis/.local/lib/python3.6/site-packages/simplejson/decoder.py", line 400, in raw_decode
	    return self.scan_once(s, idx=_w(s, idx).end())
	simplejson.errors.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

```

Thank you!

---

<div class="post-metadata">

**Author:** ![JiteshGaikwad](https://avatars.discourse-cdn.com/v4/letter/j/77aa72/32.png) [@JiteshGaikwad](https://forum.rasa.com/u/JiteshGaikwad)\
**Post date:** [December 1, 2018, 12:51pm UTC](https://forum.rasa.com/t/cors-parameter-at-nlu-api/3185/2 "2018-12-01T12:51:04Z")

</div>

can you show the command that you are running?

---

<div class="post-metadata">

**Author:** ![marcis](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/marcis/32/962_2.png) [@marcis](https://forum.rasa.com/u/marcis)\
**Post date:** [December 1, 2018, 8:32pm UTC](https://forum.rasa.com/t/cors-parameter-at-nlu-api/3185/3 "2018-12-01T20:32:39Z")

</div>

At the server:

```
python3 -m rasa_nlu.server --path my-project/models/ --cors '*'

```

At the web browser (Chrome), a jQuery call like tihs:

```
$.ajax({
    type: "POST",
    url: "http://localhost:5000/parse",
    data: {
        "q": "my question",
        "project": "my-project",
        "model": "my-model"
    },
    crossDomain: true,
    success: function (data, status, jqXHR) {
         console.log(data)
    }

```

})

Since the GET request to /status perfectly works:

```
$.ajax({
         url: "http://localhost:5000/status",
         crossDomain: true,
         success: function (data, status, jqXHR) {
             console.log(data)
         }
})
```

---

<div class="post-metadata">

**Author:** ![marcis](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/marcis/32/962_2.png) [@marcis](https://forum.rasa.com/u/marcis)\
**Post date:** [December 1, 2018, 8:36pm UTC](https://forum.rasa.com/t/cors-parameter-at-nlu-api/3185/4 "2018-12-01T20:36:34Z")

</div>

The POST request works locally if I call it with curl:

```
curl -XPOST localhost:5000/parse -d '{"q":"my question", "project":"my-project", "model":"my-model"'}
```

---

<div class="post-metadata">

**Author:** ![JiteshGaikwad](https://avatars.discourse-cdn.com/v4/letter/j/77aa72/32.png) [@JiteshGaikwad](https://forum.rasa.com/u/JiteshGaikwad)\
**Post date:** [December 2, 2018, 10:51am UTC](https://forum.rasa.com/t/cors-parameter-at-nlu-api/3185/5 "2018-12-02T10:51:52Z")

</div>

hey @marcis, the first thing you need to change is the command, you are running to start the nlu server i.e related to CORS it should be in double quotes whereas you have given it in single quote ,

**python3 -m rasa\_nlu.server --path my-project/models/ --cors "\*"**

The reason behind you are facing the problem in the jQuery call is your body part of the ajax call,you need to stringify it and then send the request :

```auto
$.ajax({
    type: "POST",
    url: "http://localhost:5000/parse",
    data:JSON.stringify( {
        "q": "my question",
        "project": "my-project",
        "model": "my-model"
    }),
    crossDomain: true,
    success: function (data, status, jqXHR) {
         console.log(data)
    }

```

}) I have tried the above code initially, i too faced the same issue while trying out your code,but i fixed it 😉

Hope this helps… 🙂

---

<div class="post-metadata">

**Author:** ![marcis](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/marcis/32/962_2.png) [@marcis](https://forum.rasa.com/u/marcis)\
**Post date:** [December 2, 2018, 11:05am UTC](https://forum.rasa.com/t/cors-parameter-at-nlu-api/3185/6 "2018-12-02T11:05:50Z")

</div>

Yes, it works! THANK YOU!!!

---

<div class="post-metadata">

**Author:** ![JiteshGaikwad](https://avatars.discourse-cdn.com/v4/letter/j/77aa72/32.png) [@JiteshGaikwad](https://forum.rasa.com/u/JiteshGaikwad)\
**Post date:** [December 2, 2018, 12:01pm UTC](https://forum.rasa.com/t/cors-parameter-at-nlu-api/3185/7 "2018-12-02T12:01:56Z")

</div>

Welcome @marcis 😁
