# Why might I be getting 400 on this request?

**URL:** https://discuss.elastic.co/t/why-might-i-be-getting-400-on-this-request/344172
**Category:** Elasticsearch
**Created:** [September 30, 2023, 2:44pm UTC](https://discuss.elastic.co/t/why-might-i-be-getting-400-on-this-request/344172 "2023-09-30T14:44:39Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![mrodent](https://avatars.discourse-cdn.com/v4/letter/m/65b543/32.png) [@mrodent](https://discuss.elastic.co/u/mrodent)
#### Post date: [September 30, 2023, 2:44pm UTC](https://discuss.elastic.co/t/why-might-i-be-getting-400-on-this-request/344172/1 "2023-09-30T14:44:39Z")

</div>

ES 8.6.2.

Low-level user here. I'm trying to clone and then delete in order to rename an index.  
Before cloning I'm told ([here](https://stackoverflow.com/a/70018231/595305)) I should execute this "index.blocks.write" command.

This is my attempt (Python):

```auto
        ES_URL = 'https://localhost:9500' # yes, running on that Port
        TEMP_INDEX_NAME = 'temp_index'
        data = {
            'settings': {
              'index.blocks.write': True,
            }            
        }
        headers = {'Content-type': 'application/json'}
        # NB the auth and verify stuff is definitely working
        requests.put(f'{ES_URL}/{TEMP_INDEX_NAME}/_settings', data=data, headers=headers, auth=auth, verify=verify)

```

... gets 400 "Bad Request"

And in fact, if I omit that, and just try for the clone, I also get 400:

```
    requests.post(f'{ES_URL}/{TEMP_INDEX_NAME}/_clone/my_new_index', auth=auth, verify=verify)

```

Is there maybe something I need to enable in the configuration of ES?

---

<div class="post-metadata">

### Author: ![leandrojmp](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/leandrojmp/32/107231_2.png) [@leandrojmp](https://discuss.elastic.co/u/leandrojmp)
#### Post date: [September 30, 2023, 3:32pm UTC](https://discuss.elastic.co/t/why-might-i-be-getting-400-on-this-request/344172/2 "2023-09-30T15:32:47Z")

</div>

> [@mrodent](#):
>
> ```auto
> data = {
> 'settings': {
> 'index.blocks.write': True,
> }            
> }
> 
> ```

The payload is wrong, there is no top-level `settings` and also there is a comma after _True_, but you do not have another item. [[check the documentation](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-update-settings.html)].

You may try with one of these payloads:

```auto
        data = {
            'index': {
              'blocks.write': true
            }            
        }

```

```auto
        data = {
              'index.blocks.write': true
        }

```

---

<div class="post-metadata">

### Author: ![mrodent](https://avatars.discourse-cdn.com/v4/letter/m/65b543/32.png) [@mrodent](https://discuss.elastic.co/u/mrodent)
#### Post date: [September 30, 2023, 5:04pm UTC](https://discuss.elastic.co/t/why-might-i-be-getting-400-on-this-request/344172/3 "2023-09-30T17:04:25Z")

</div>

Thanks very much. This is very puzzling. I tried various permutations of what you suggested. `true` (lower-case "t") on its own doesn't work in Python: it is illegal. But I tried with the string "true".

Also, in Python, a dictionary (`dict`) takes no account of a trailing comma after the last key-value pair.

But I tried with both `True` and string "true" with both your suggestions. And I'm still getting 400.

PS I also checked out that documentation page you linked to. But it's quite general, not covering "blocks.write" stuff.

---

<div class="post-metadata">

### Author: ![mrodent](https://avatars.discourse-cdn.com/v4/letter/m/65b543/32.png) [@mrodent](https://discuss.elastic.co/u/mrodent)
#### Post date: [October 1, 2023, 7:29am UTC](https://discuss.elastic.co/t/why-might-i-be-getting-400-on-this-request/344172/4 "2023-10-01T07:29:17Z")

</div>

I found the solution. In fact this command (as suggested by leandrojmp) worked fine when I ran it in Insomnia... but not when I use Python code. Checking various questions on this at Stack Overflow I found the solution:

```
    data = json.dumps({
        'index': {
            'blocks.write': True
        }
    })

```

... i.e. submitting the `dict` didn't work. Submitting a string of the `dict` does. This is extremely surprising as I've been using `dict` directly since... years! (and have never encountered this issue before ever, to my knowledge).

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [October 29, 2023, 7:30am UTC](https://discuss.elastic.co/t/why-might-i-be-getting-400-on-this-request/344172/5 "2023-10-29T07:30:03Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
