# \[Question\] Python - weaviate client 4.0 cannot connect from inside kubernetes

**URL:** <https://forum.weaviate.io/t/question-python-weaviate-client-4-0-cannot-connect-from-inside-kubernetes/3335>\
**Category:** Support\
**Tags:** technical\
**Created:** [August 12, 2024, 5:09pm UTC](https://forum.weaviate.io/t/question-python-weaviate-client-4-0-cannot-connect-from-inside-kubernetes/3335 "2024-08-12T17:09:31Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![marekzebrowski](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.weaviate.io/marekzebrowski/32/2113_2.png) [@marekzebrowski](https://forum.weaviate.io/u/marekzebrowski)\
**Post date:** [August 12, 2024, 5:09pm UTC](https://forum.weaviate.io/t/question-python-weaviate-client-4-0-cannot-connect-from-inside-kubernetes/3335/1 "2024-08-12T17:09:31Z")

</div>

I have a behavior that I can’t explain:  
I have a docker image - python:3.11 weaviate client 4.7.1

code is super simple:

````auto
client = weaviate.connect_to_weaviate_cloud(
    cluster_url=WV_URL, # Replace with your Weaviate Cloud URL
    auth_credentials=Auth.api_key(WV_APIKEY), 
)```

and the best part - the same docker image when run locally connects fine, but run from other environment - inside kubernetes on amazon fails with:

````

`Traceback (most recent call last):`

`File "/app/server.py", line 21, in <module>`

`client = weaviate.connect_to_weaviate_cloud(`

`^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^`

`File "/usr/local/lib/python3.11/site-packages/weaviate/connect/helpers.py", line 79, in connect_to_weaviate_cloud`

`return __connect(`

`^^^^^^^^^^`

`File "/usr/local/lib/python3.11/site-packages/weaviate/connect/helpers.py", line 410, in __connect`

`raise e`

`File "/usr/local/lib/python3.11/site-packages/weaviate/connect/helpers.py", line 406, in __connect`

`client.connect()`

`File "/usr/local/lib/python3.11/site-packages/weaviate/syncify.py", line 23, in sync_method`

`return _EventLoopSingleton.get_instance().run_until_complete(`

`^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^`

`File "/usr/local/lib/python3.11/site-packages/weaviate/event_loop.py", line 40, in run_until_complete`

`return fut.result()`

`^^^^^^^^^^^^`

`File "/usr/local/lib/python3.11/concurrent/futures/_base.py", line 456, in result`

`return self.__get_result()`

`^^^^^^^^^^^^^^^^^^^`

`File "/usr/local/lib/python3.11/concurrent/futures/_base.py", line 401, in __get_result`

`raise self._exception`

`File "/usr/local/lib/python3.11/site-packages/weaviate/client_base.py", line 152, in connect`

`await self._connection.connect(self._skip_init_checks)`

`File "/usr/local/lib/python3.11/site-packages/weaviate/connect/v4.py", line 146, in connect`

`await self._open_connections(self._auth, skip_init_checks)`

`File "/usr/local/lib/python3.11/site-packages/weaviate/connect/v4.py", line 239, in _open_connections`

`self.__make_clients()`

`File "/usr/local/lib/python3.11/site-packages/weaviate/connect/v4.py", line 228, in __make_clients`

`self._client = self.__make_async_client()`

`^^^^^^^^^^^^^^^^^^^^^^^^^^`

`File "/usr/local/lib/python3.11/site-packages/weaviate/connect/v4.py", line 222, in __make_async_client`

`return AsyncClient(`

`^^^^^^^^^^^^`

`File "/usr/local/lib/python3.11/site-packages/httpx/_client.py", line 1389, in __init__ `

`super(). __init__ (`

`File "/usr/local/lib/python3.11/site-packages/httpx/_client.py", line 183, in __init__ `

`self.headers = Headers(headers)`

`^^^^^^^^^^^^^^^^`

`File "/usr/local/lib/python3.11/site-packages/httpx/_models.py", line 72, in __init__ `

`self._list = [`

`^`

`File "/usr/local/lib/python3.11/site-packages/httpx/_models.py", line 76, in <listcomp>`

`normalize_header_value(v, encoding),`

`^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^`

`File "/usr/local/lib/python3.11/site-packages/httpx/_utils.py", line 53, in normalize_header_value`

`return value.encode(encoding or "ascii")`

```auto

Probably environment error, but is there a way to debug it ?
```

---

<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:** [August 12, 2024, 7:51pm UTC](https://forum.weaviate.io/t/question-python-weaviate-client-4-0-cannot-connect-from-inside-kubernetes/3335/2 "2024-08-12T19:51:42Z")

</div>

hi @marekzebrowski !!

Welcome to our community 🤗

the `connect_to_weaviate_cloud` should **only** be used when connecting to our cloud.

And thats because we have a specific way of exposing our weaviate instances, [as you can see here](https://github.com/weaviate/weaviate-python-client/blob/5482164c2732db8ea9ce66b1c4743a4c2140b8ac/weaviate/connect/helpers.py#L14).

If you expose your cluster exactly like we do in our cloud, you could also use that method too.

So `client.connect_to*` methods will “configure” how the client connects to the server.

With that said, you will want to take a look at `connect_to_custom`, and provide all the hosts/ports/security you have used to properly expose your Weaviate cluster.

Check here for more on [connect\_to\_custom](https://weaviate.io/developers/weaviate/client-libraries/python#connection-helper-functions)

for example, this is the equivalent to `connect_to_local`

```python
import weaviate

client = weaviate.connect_to_custom(
    http_host="localhost",
    http_port="8080",
    http_secure=False,
    grpc_host="localhost",
    grpc_port="50051",
    grpc_secure=False,
    headers={
        "X-OpenAI-Api-Key": os.getenv("OPENAI_APIKEY") # Or any other inference API keys
    }
)

```

Let me know if this helps 🙂

Thanks!

---

<div class="post-metadata">

**Author:** ![marekzebrowski](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.weaviate.io/marekzebrowski/32/2113_2.png) [@marekzebrowski](https://forum.weaviate.io/u/marekzebrowski)\
**Post date:** [August 12, 2024, 9:49pm UTC](https://forum.weaviate.io/t/question-python-weaviate-client-4-0-cannot-connect-from-inside-kubernetes/3335/3 "2024-08-12T21:49:23Z")

</div>

but… I am trying to connect to weaviate cloud - in both cases. `wqpzmrins6y4jyhqg4pvcw.c0.europe-west3.gcp.weaviate.cloud` to be specific.

I don’t expect anything special in the client - I suspect networking inside k8s to be tainted. I just wonder if there is a way to debug such problem - like debug log or something similar.

---

<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:** [August 12, 2024, 11:16pm UTC](https://forum.weaviate.io/t/question-python-weaviate-client-4-0-cannot-connect-from-inside-kubernetes/3335/4 "2024-08-12T23:16:40Z")

</div>

Oh @marekzebrowski !! I am really sorry.

I though you were running Weaviate on Kubernetes 🙈

Weaviate will provide basically two endpoints, HTTP and GRPC.

for testing http a simple curl to the endpoint will be enough.

For GRPC, you can use a tool called grpcurl.

on this thread there is an explanation on how to do that:

> [@Weaviate with Traefik and gRPC](https://forum.weaviate.io/t/weaviate-with-traefik-and-grpc/1238/3):
>
> Hi @qnlbnsl ! Sorry for the delay here. Looks like I was finally able to tame this Here is what I got: NOTE: [Check this updated gist on how to correctly expose Weaviate under SSL/TLS using Traefik and running everything with a docker compose](https://gist.github.com/dudanogueira/0dd925cbf63397e256e84e991245aab3/edit) --- version: '3.4' services: weaviate: command: - --host - 0.0.0.0 - --port - '8080' - --scheme - http image: semitechnologies/weaviate:1.23.5 #ports: # - 8081:8080 # unsafe http # - 50052:50051 # unsafe grpc…

Let me know if this heps.

---

<div class="post-metadata">

**Author:** ![ajay](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.weaviate.io/ajay/32/2468_2.png) [@ajay](https://forum.weaviate.io/u/ajay)\
**Post date:** [October 7, 2024, 10:39am UTC](https://forum.weaviate.io/t/question-python-weaviate-client-4-0-cannot-connect-from-inside-kubernetes/3335/5 "2024-10-07T10:39:43Z")

</div>

@marekzebrowski Is this issue resolved? I am also facing similar issue.

---

<div class="post-metadata">

**Author:** ![marekzebrowski](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.weaviate.io/marekzebrowski/32/2113_2.png) [@marekzebrowski](https://forum.weaviate.io/u/marekzebrowski)\
**Post date:** [October 7, 2024, 11:52am UTC](https://forum.weaviate.io/t/question-python-weaviate-client-4-0-cannot-connect-from-inside-kubernetes/3335/6 "2024-10-07T11:52:32Z")

</div>

YES. It turned out to be bad decoding of AWS secret, that mangled API key.  
in AWS use none instead of auto - that helped me.

---

<div class="post-metadata">

**Author:** ![ajay](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.weaviate.io/ajay/32/2468_2.png) [@ajay](https://forum.weaviate.io/u/ajay)\
**Post date:** [October 7, 2024, 2:53pm UTC](https://forum.weaviate.io/t/question-python-weaviate-client-4-0-cannot-connect-from-inside-kubernetes/3335/7 "2024-10-07T14:53:38Z")

</div>

do you mean weaviate api key was incorrect that was read from AWS secret? I did not follow you completely.

---

<div class="post-metadata">

**Author:** ![marekzebrowski](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.weaviate.io/marekzebrowski/32/2113_2.png) [@marekzebrowski](https://forum.weaviate.io/u/marekzebrowski)\
**Post date:** [October 7, 2024, 6:18pm UTC](https://forum.weaviate.io/t/question-python-weaviate-client-4-0-cannot-connect-from-inside-kubernetes/3335/8 "2024-10-07T18:18:56Z")

</div>

Exactly. Root cause of my problem was decoding of AWS secret. In that secret I stored Weaviate api key.

---

<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:** [October 14, 2024, 9:17pm UTC](https://forum.weaviate.io/t/question-python-weaviate-client-4-0-cannot-connect-from-inside-kubernetes/3335/9 "2024-10-14T21:17:03Z")

</div>

Thanks for sharing, @marekzebrowski !!!
