# Using ray.cloudpickle methods in the serve deployment - error

**URL:** <https://discuss.ray.io/t/using-ray-cloudpickle-methods-in-the-serve-deployment-error/5285>\
**Category:** Ray Clusters\
**Created:** [March 3, 2022, 10:57pm UTC](https://discuss.ray.io/t/using-ray-cloudpickle-methods-in-the-serve-deployment-error/5285 "2022-03-03T22:57:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mkir](https://avatars.discourse-cdn.com/v4/letter/m/838e76/32.png) [@mkir](https://discuss.ray.io/u/mkir)\
**Post date:** [March 3, 2022, 10:57pm UTC](https://discuss.ray.io/t/using-ray-cloudpickle-methods-in-the-serve-deployment-error/5285/1 "2022-03-03T22:57:58Z")

</div>

As soon as I use ray.cloudpickle.dumps/loads methods, the error about `Ray Client is not connected` is reported.

```auto
Ray Client is not connected. Please connect by calling `ray.init`.

```

Env: a ray cluster (head with 2 workers) on k3s installed with ray operator. Code is run from a juypyter notebook on the ray head.

In contrast, running similar code on a local machine ray does not have issue using ray.cloudpickle methods.

Here’s the serve deployment. In the current state, it produces the error. If I comment out the lines with cloudpickle and run the ones with ray.get/put - no problems.

```auto
import ray
from ray import serve
import json

# Connect to cluster
try:
    # runtime_env = {"pip":["ruptures","pathos"]}
    ray_client = ray.init(f"ray://localhost:10001", namespace="serve")
except Exception as e:
    print("Exception",e)
    pass
finally:
    print("Ray serve started")
    client = serve.start(detached=True, http_options={"host": "0.0.0.0"})

@serve.deployment(route_prefix="/lastchunker")
class LastChunker:
    async def __call__ (self, request):
        try:
            raw_json = await request.json()
            id_str = raw_json.get('store_id')
            id_pkld = base64.b64decode(id_str.encode())
            id_restored = ray.cloudpickle.loads(id_pkld)
            ray_data = ray.get(id_restored
            # one = ray.put(1)
            
            return {"ray_data": ray_data}
            # return {"ray_data": ray.get(one)}
        except Exception as ex:
            return {"error": ex}

LastChunker.deploy()

```

Here is the calling code:

```auto
import requests
import base64

f = ray.put("foo")
print(f"f: {f}")
fpikl = ray.cloudpickle.dumps(f)
print(f"fpikl: {fpikl}")

b64fpkl = base64.b64encode(fpikl).decode()
print(f"b64fpkl: {b64fpkl}")

data='{"store_id": "' + f"{b64fpkl}" +'"}'
print(f"data: {data}")

id_str = json.loads(data).get('store_id')
print (f"id_str: {id_str}")

id_pkld = base64.b64decode(id_str.encode())
print(f"id_pkld: {id_pkld}")

id_restored = ray.cloudpickle.loads(id_pkld)
print(f"id_restored: {id_restored}")

resp = requests.get("http://localhost:8000/lastchunker", data=data)
resp.json()

```

---

<div class="post-metadata">

**Author:** ![mkir](https://avatars.discourse-cdn.com/v4/letter/m/838e76/32.png) [@mkir](https://discuss.ray.io/u/mkir)\
**Post date:** [March 4, 2022, 6:26pm UTC](https://discuss.ray.io/t/using-ray-cloudpickle-methods-in-the-serve-deployment-error/5285/2 "2022-03-04T18:26:48Z")

</div>

I was able to get past the `Ray is not connected` error by calling `ray.shutdown()` after deploying the model and then doing `ray.init()` in the calling code.

The ray.cloudpickle.get() call works, but the ray.get() is not able to find the object, but rather now have the error

```auto
(raylet, ip=10.42.1.28) [2022-03-04 10:07:57,747 E 127 127] object_manager.cc:261: 
Couldn't send pull request from 
143716f6b723ac70e631505b86f8adbf0334549cc7a75edc7fe932ec 
to 
38ba8defd158a418425b79207dd50532e8e6953cecd58d8992631e49 
of object ffffffffffffffffffffffffffffffffffffffff0100000001000000 , 
setup rpc connection failed.

```

---

<div class="post-metadata">

**Author:** ![mkir](https://avatars.discourse-cdn.com/v4/letter/m/838e76/32.png) [@mkir](https://discuss.ray.io/u/mkir)\
**Post date:** [March 9, 2022, 8:08pm UTC](https://discuss.ray.io/t/using-ray-cloudpickle-methods-in-the-serve-deployment-error/5285/3 "2022-03-09T20:08:14Z")

</div>

I think I figured out why the objects cannot be found… SHHH… Don’t tell anyone. The python that was running the client code had not called ray start to connect to the cluster.
