# Python client write error - Node not found for partition

**URL:** <https://discuss.aerospike.com/t/python-client-write-error-node-not-found-for-partition/7507>\
**Category:** General Discussion\
**Tags:** python\
**Created:** [June 4, 2020, 2:36pm UTC](https://discuss.aerospike.com/t/python-client-write-error-node-not-found-for-partition/7507 "2020-06-04T14:36:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pradeep\_Banavara](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/pradeep_banavara/32/1386_2.png) [@Pradeep\_Banavara](https://discuss.aerospike.com/u/Pradeep_Banavara)\
**Post date:** [June 4, 2020, 2:36pm UTC](https://discuss.aerospike.com/t/python-client-write-error-node-not-found-for-partition/7507/1 "2020-06-04T14:36:34Z")

</div>

I have a 3 node Aerospike community cluster on AWS with the following config

- **instance\_type** - default = c5d.large
- **cluster\_hosts\_per\_az** - default = 1
- **partitions\_per\_device** - default = 4 ( nvme volumes will automatically be partitioned for you )
- **enterprise** - default = false to allow single click setup of Community. If true, a feature key location must be specified ( see below )
- **encryption\_at\_rest** - default = false. If true `aerospike.conf` will be appropriately modified and a key file generated
- **tls\_enabled** - default = false. If true `aerospike.conf` will be appropriately modified and all certificates appropriately located. Connecting clients will be appropriately configured.
- **strong\_consistency** - default = false. If true `aerospike.conf` will be appropriately modified. You will currently have to set your own roster.
- **monitoring\_enabled** - default = false. If true the Aerospike Prometheus agent will be installed, configured and started on the cluster nodes.
- **aerospike\_distribution** - default = el6. Determines the distribution used.
- **aerospike\_version** - default = latest
- **ami\_locator\_string** - the latest version of the AMZN2 AMI is used ( dynamically looked up). Other builds can be used by modifying this string.
- **replication\_factor** - default = 2
- **aerospike\_mem\_pct** - fraction of available memory to allocate to the ‘test namespace’. Default = 80%
- **feature\_key** - path for an Enterprise feature key. Undefined by default so the setup works out of the box.

I have a t2-medium machine in the same region running the python client. The client is a FastAPI webapp. The object I am writing is a simple dict. I create a unique key for every write and thus

```auto
@app.post('/')
def post_data(item: Item):
    pk = None
    try:
        i = item.dict()
        pk = str(shortuuid.uuid())
        key = ('test', 'pydemo', pk)
        client.put(key, i)
        return {"message": "Write success", "key": pk}
    except Exception as e:
        print("Error while inserting pk {} ::: {}".format(pk, e))
        return {"error": e}

```

Everything goes fine with writes and reads but once I start hitting simultaneous writes using Apache bench - I get the following error

```auto
(-8, 'Node not found for partition test:3023', 'src/main/client/put.c', 111, False)

```

Any help is appreciated. I am not closing the connection anywhere. Here is the full code

```auto
from fastapi import FastAPI
import aerospike
from pydantic import BaseModel
import shortuuid

class Item(BaseModel):
    name: str
    description: str = None
    price: float
    tax: float = None

app = FastAPI()

aero_config = {"hosts": [("100.26.108.213", 3000)] }

try:
    client = aerospike.client(aero_config).connect()

except Exception as e:
    print(e)

@app.post('/')
def post_data(item: Item):
    pk = None
    try:
        i = item.dict()
        pk = str(shortuuid.uuid())
        key = ('test', 'pydemo', pk)
        client.put(key, i)
        return {"message": "Write success", "key": pk}
    except Exception as e:
        print("Error while inserting pk {} ::: {}".format(pk, e))
        return {"error": e}

@app.get('/')
def read_root(pk: str):
    try:
        key = ('test', 'demo', pk)
        _, _, result = client.get(key)
        return {"message": result}
    except Exception as e:
        return {"message": "error in read"}

```

---

<div class="post-metadata">

**Author:** ![Pradeep\_Banavara](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/pradeep_banavara/32/1386_2.png) [@Pradeep\_Banavara](https://discuss.aerospike.com/u/Pradeep_Banavara)\
**Post date:** [June 9, 2020, 9:30am UTC](https://discuss.aerospike.com/t/python-client-write-error-node-not-found-for-partition/7507/2 "2020-06-09T09:30:14Z")

</div>

TIL - on any public cloud infra when using public IPs to connect it’s best to specify the use-alternate-address and specify the public interface for Aerospike. I don’t know why this is the case, will dig in a bit more. So I changed the config on all 3 machines to

```auto
 service {
                address eth0
                port 3000
                alternate-access-address <public host IP>
        }

```

and in the client I specified `'use_services_alternate':True`

Seems to work - At least am not seeing the partition errors that I saw earlier

---

<div class="post-metadata">

**Author:** ![meher](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/meher/32/1644_2.png) [@meher](https://discuss.aerospike.com/u/meher)\
**Post date:** [June 11, 2020, 2:17am UTC](https://discuss.aerospike.com/t/python-client-write-error-node-not-found-for-partition/7507/3 "2020-06-11T02:17:36Z")

</div>

This is because if the client cannot see the private IP, it would need the public one… the alternate-access-address allows you to specify that.
