# Getting 401 error with data insertion

**URL:** <https://forum.weaviate.io/t/getting-401-error-with-data-insertion/3091>\
**Category:** Support\
**Created:** [July 18, 2024, 1:27pm UTC](https://forum.weaviate.io/t/getting-401-error-with-data-insertion/3091 "2024-07-18T13:27:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![aparna\_raj](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.weaviate.io/aparna_raj/32/1983_2.png) [@aparna\_raj](https://forum.weaviate.io/u/aparna_raj)\
**Post date:** [July 18, 2024, 1:27pm UTC](https://forum.weaviate.io/t/getting-401-error-with-data-insertion/3091/1 "2024-07-18T13:27:17Z")

</div>

### Description

We are using an on prem instance of weaviate. We were able to do some data insertion and retrieval but started getting 401 error and unable to identify the root cause. using multi tenancy model here. here are the error logs for reference.

eaviate.exceptions.WeaviateQueryError: Query call with protocol GQL Aggregate failed with message Error in GraphQL response: [  
{  
“locations”: [  
{  
“column”: 12,  
“line”: 1  
}  
],  
“message”: "shard Tenantname: status code: 401, error: ",  
“path”: [  
“Aggregate”,  
“collection1”  
]  
}  
], for the following query: {Aggregate{NaaS1(tenant: “Tname”){meta{count}}}}.  
sys:1: ResourceWarning: unclosed \<ssl.SSLSocket fd=4, family=2, type=1, proto=0, laddr=(‘10.110.183.26’, 53626), raddr=(‘173.37.11.56’, 6380

Any guidance on this error is much appreciated.

---

<div class="post-metadata">

**Author:** ![DudaNogueira](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.weaviate.io/dudanogueira/32/7846_2.png) [@DudaNogueira](https://forum.weaviate.io/u/DudaNogueira)\
**Post date:** [July 18, 2024, 1:41pm UTC](https://forum.weaviate.io/t/getting-401-error-with-data-insertion/3091/2 "2024-07-18T13:41:53Z")

</div>

hi @aparna_raj !!

Welcome to our community!

Please, when asking for support in forums, always fill in the requested infos like version, deployment, etc.

Please, can you share the code used for creating the collection, tenant and ingesting some data?

THanks!

---

<div class="post-metadata">

**Author:** ![aparna\_raj](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.weaviate.io/aparna_raj/32/1983_2.png) [@aparna\_raj](https://forum.weaviate.io/u/aparna_raj)\
**Post date:** [July 18, 2024, 3:41pm UTC](https://forum.weaviate.io/t/getting-401-error-with-data-insertion/3091/3 "2024-07-18T15:41:50Z")

</div>

Hi Duda

Please find the details below

Weaviate Server Version: 1.25.7

Deployment Method: k8s

Multi Node? Number of Running Nodes: 3

Client Language and Version: Python 3.12

Multitenancy?: yes

# Create multi-tenancy Cluster

```
def create_collection(client, tenant):
     if client.collections.exists("collname"):
        client.collections.delete("collname ")

coll = client.collections.create(
    name=" collname ",
    multi_tenancy_config=Configure.multi_tenancy(
        enabled=True,
        auto_tenant_activation=True
    ),
    # Enabling the vectorizer
   
    vectorizer_config=wc.Configure.Vectorizer.text2vec_cohere(model="embed-english-v3.0"),
    generative_config=wc.Configure.Generative.cohere(model="command-xlarge-nightly"),

    properties=[
        wc.Property(name="source", data_type=wc.DataType.TEXT),
        wc.Property(name="raw_text", data_type=wc.DataType.TEXT),
    ],
)

# Create a tenant inside a collection
coll.tenants.create(
    tenants=[
        Tenant(name=tenant)
    ]
)
tenants = coll.tenants.get()
print(tenants)

print("Collection created successfully: collname")

```

# Inserting the data in Multi tenant collection

def insert\_data(wvc, content, tenant):  
uuid\_lst =

```
base_coll = wvc.collections.get("collname")
collection = base_coll.with_tenant(tenant)

# Insert the data objects
with collection.batch.fixed_size(
        batch_size=50,
        # concurrent_requests=1
) as batch:
    batch.add_object(content)

#import pdb; pdb.set_trace()
print("Data inserted successfully: collname ")

if len(collection.batch.failed_objects) > 0:
    print("Failed to insert data")
    for failed_object in collection.batch.failed_objects:
        print(failed_object)

print(collection.aggregate.over_all())

return collection

```
