# Python Client - unable to remove "read\_only" block

**URL:** <https://discuss.elastic.co/t/python-client-unable-to-remove-read-only-block/288032>\
**Category:** Elasticsearch\
**Tags:** language-clients\
**Created:** [October 29, 2021, 6:52pm UTC](https://discuss.elastic.co/t/python-client-unable-to-remove-read-only-block/288032 "2021-10-29T18:52:29Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![philhagen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/philhagen/32/96548_2.png) [@philhagen](https://discuss.elastic.co/u/philhagen)\
**Post date:** [October 29, 2021, 6:52pm UTC](https://discuss.elastic.co/t/python-client-unable-to-remove-read-only-block/288032/1 "2021-10-29T18:52:29Z")

</div>

When using the official Python client, I can't seem to find a way to change an index to normal "read-write" status once it's been marked "read\_only".

[This function](https://github.com/elastic/elasticsearch-py/blob/a8a828805afb0adf4c0380c025fd247a2a830778/elasticsearch/_sync/client/indices.py#L1468) works fine to go from read-write to read\_only, but I was unable to identify any method to reverse it.

I can accomplish this in curl with something like the following:  
`curl -s -H 'kbn-xsrf: true' -H 'Content-Type: application/json' -X PUT http://localhost:9200/my-index-2020.09/_settings -d '{ "index": { "blocks.read_only": false } }'`

Thanks for any pointers you might have on this one!

---

<div class="post-metadata">

**Author:** ![philhagen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/philhagen/32/96548_2.png) [@philhagen](https://discuss.elastic.co/u/philhagen)\
**Post date:** [October 30, 2021, 10:05pm UTC](https://discuss.elastic.co/t/python-client-unable-to-remove-read-only-block/288032/2 "2021-10-30T22:05:34Z")

</div>

For added context, this is what I have tried so far.

```auto
>>> es.indices.add_block(index='name', block="read_only")
{'acknowledged': True, 'shards_acknowledged': True, 'indices': [{'name': 'name', 'blocked': True}]}
>>> es.indices.put_settings(index=name', body='{"blocks": { "read_only": true } }')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/elk_user/.local/lib/python3.6/site-packages/elasticsearch/client/utils.py", line 301, in _wrapped
    return func(*args, params=params, headers=headers, **kwargs)
  File "/home/elk_user/.local/lib/python3.6/site-packages/elasticsearch/client/indices.py", line 811, in put_settings
    body=body,
  File "/home/elk_user/.local/lib/python3.6/site-packages/elasticsearch/transport.py", line 458, in perform_request
    raise e
  File "/home/elk_user/.local/lib/python3.6/site-packages/elasticsearch/transport.py", line 426, in perform_request
    timeout=timeout,
  File "/home/elk_user/.local/lib/python3.6/site-packages/elasticsearch/connection/http_urllib3.py", line 287, in perform_request
    self._raise_error(response.status, raw_data)
  File "/home/elk_user/.local/lib/python3.6/site-packages/elasticsearch/connection/base.py", line 338, in _raise_error
    status_code, error_message, additional_info
elasticsearch.exceptions.AuthorizationException: AuthorizationException(403, 'cluster_block_exception', 'index [name] blocked by: [FORBIDDEN/5/index read-only (api)];')

```

However, the following works at a bash prompt:

```auto
curl -s -H 'kbn-xsrf: true' -H 'Content-Type: application/json' -X PUT http://localhost:9200/name/_settings -d '{ "index": { "blocks.read_only": false } }'
{"acknowledged": true}

```

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [November 1, 2021, 4:23am UTC](https://discuss.elastic.co/t/python-client-unable-to-remove-read-only-block/288032/3 "2021-11-01T04:23:59Z")

</div>

At a guess, we didn't allow that because this sort of action is typically an admin level one only, not something you'd want to give to a client.

---

<div class="post-metadata">

**Author:** ![philhagen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/philhagen/32/96548_2.png) [@philhagen](https://discuss.elastic.co/u/philhagen)\
**Post date:** [November 2, 2021, 3:10pm UTC](https://discuss.elastic.co/t/python-client-unable-to-remove-read-only-block/288032/4 "2021-11-02T15:10:29Z")

</div>

Hmm, ok. Curious why setting the read-only would be supported but not the reverse. Especially since the action can be done via curl. (Suggesting to me that the python client is returning the denial rather than ES itself, but I admit that's speculation.)

I'm kind of hoping not to write a python script that can do everything except reverting to R-W, which has to be done via a subprocess call to curl.

---

<div class="post-metadata">

**Author:** ![philhagen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/philhagen/32/96548_2.png) [@philhagen](https://discuss.elastic.co/u/philhagen)\
**Post date:** [November 3, 2021, 9:56pm UTC](https://discuss.elastic.co/t/python-client-unable-to-remove-read-only-block/288032/5 "2021-11-03T21:56:55Z")

</div>

I guess a better way to ask this, is:  
Does this sound like an issue to file for a missing comparative feature within the Python client?

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [November 3, 2021, 11:42pm UTC](https://discuss.elastic.co/t/python-client-unable-to-remove-read-only-block/288032/6 "2021-11-03T23:42:40Z")

</div>

Yeah, I would suggest that'd be worth raising.

---

<div class="post-metadata">

**Author:** ![philhagen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/philhagen/32/96548_2.png) [@philhagen](https://discuss.elastic.co/u/philhagen)\
**Post date:** [November 4, 2021, 9:34pm UTC](https://discuss.elastic.co/t/python-client-unable-to-remove-read-only-block/288032/7 "2021-11-04T21:34:21Z")

</div>

Thanks, Mark - I appreciate it. For awareness/future searches, the issue is here: [Cannot remove `read_only` block on an index · Issue #1788 · elastic/elasticsearch-py · GitHub](https://github.com/elastic/elasticsearch-py/issues/1788)

---

<div class="post-metadata">

**Author:** ![sethmlarson](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sethmlarson/32/93342_2.png) [@sethmlarson](https://discuss.elastic.co/u/sethmlarson)\
**Post date:** [November 4, 2021, 9:51pm UTC](https://discuss.elastic.co/t/python-client-unable-to-remove-read-only-block/288032/8 "2021-11-04T21:51:34Z")

</div>

We were able to solve this issue, there was a typo in the request using the Python client attempting to set the `blocks.read_only` setting instead of the full `index.blocks.read_only` setting. Combine that with Elasticsearch favoring raising the "this index is read-only" error over the "this setting doesn't exist" error.

---

<div class="post-metadata">

**Author:** ![sethmlarson](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sethmlarson/32/93342_2.png) [@sethmlarson](https://discuss.elastic.co/u/sethmlarson)\
**Post date:** [November 4, 2021, 10:02pm UTC](https://discuss.elastic.co/t/python-client-unable-to-remove-read-only-block/288032/9 "2021-11-04T22:02:27Z")

</div>

After a tiny bit more digging, this may actually be a bug. Detailed in this issue: [Unblocking an index using 'blocks.read\_only: false' doesn't work like 'index.blocks.read\_only: false' · Issue #80383 · elastic/elasticsearch · GitHub](https://github.com/elastic/elasticsearch/issues/80383)

---

<div class="post-metadata">

**Author:** ![philhagen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/philhagen/32/96548_2.png) [@philhagen](https://discuss.elastic.co/u/philhagen)\
**Post date:** [November 5, 2021, 8:29pm UTC](https://discuss.elastic.co/t/python-client-unable-to-remove-read-only-block/288032/10 "2021-11-05T20:29:18Z")

</div>

Thanks again for your help on this. Implemented a fix and seems to be working as intended. Much appreciated!

---

<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:** [December 3, 2021, 8:29pm UTC](https://discuss.elastic.co/t/python-client-unable-to-remove-read-only-block/288032/11 "2021-12-03T20:29:56Z")

</div>

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