# Ray serve : Request Object has no attribute data

**URL:** <https://discuss.ray.io/t/ray-serve-request-object-has-no-attribute-data/931>\
**Category:** Ray Serve\
**Created:** [February 18, 2021, 8:06pm UTC](https://discuss.ray.io/t/ray-serve-request-object-has-no-attribute-data/931 "2021-02-18T20:06:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![AmauryFaure](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/amauryfaure/32/479_2.png) [@AmauryFaure](https://discuss.ray.io/u/AmauryFaure)\
**Post date:** [February 18, 2021, 8:06pm UTC](https://discuss.ray.io/t/ray-serve-request-object-has-no-attribute-data/931/1 "2021-02-18T20:06:16Z")

</div>

Hello !

I am trying to implement a serving for a NLP model I trained, i’m inspiring myself of this for the serving part : [Code Example](https://github.com/anyscale/e2e-nlp-template/blob/master/example.ipynb)

I have made the following code :

```auto
from transformers import CamembertForSequenceClassification,CamembertTokenizer
import ray
from ray import serve
import requests
import argparse
import torch

args=argparse.Namespace()
use_gpu = torch.cuda.is_available()
args.device = torch.device("cuda" if use_gpu else "cpu")

client=serve.start()

class predict_class:
    def __init__ (self,args):
        self.args=args
        self.model=CamembertForSequenceClassification.from_pretrained("/home/amaury/Documents/project_a1/camembert-v1")
        self.tokenizer=CamembertTokenizer.from_pretrained("camembert-base")
        self.model.to(args.device)

    def __call__ (self,flask_request):
        input=flask_request.data.decode("utf-8")
        
        tokenized=self.tokenizer(input)
        text=torch.tensor([tokenized]).to(args.device)

        result=self.model(text)
        return(result)

client.create_backend("classpredict", predict_class, args, ray_actor_options={"num_gpus": 1})
client.create_endpoint("classpredict",backend="classpredict", route="/classpredict",methods=["GET","POST"])

r=requests.post("http://127.0.0.1:8000/classpredict",data="hello")
r.content

```

I’m getting the following error : AttributeError: ‘Request’ object has no attribute ‘data’

I do not get why or what it is that i’m doing differently that might be linked to this.  
Thanks in advance for your help ! sorry if this was already brought up, i did not find anything regarding this.

---

<div class="post-metadata">

**Author:** ![architkulkarni](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/architkulkarni/32/10_2.png) [@architkulkarni](https://discuss.ray.io/u/architkulkarni)\
**Post date:** [February 18, 2021, 8:20pm UTC](https://discuss.ray.io/t/ray-serve-request-object-has-no-attribute-data/931/2 "2021-02-18T20:20:22Z")

</div>

Hello!

The Ray Serve API changed a little bit since that example code was posted. As of Ray version 1.2.0, Ray Serve now uses a Starlette request object instead of a Flask request object. Here’s the migration guide: [Ray Serve Request Migration Guide - Google Docs](https://docs.google.com/document/d/1CG4y5WTTc4G_MRQGyjnb_eZ7GK3G9dUX6TNLKLnKRAc/edit)

For your specific error, you’ll want to use `await request.body()` instead of `request.data`.

---

<div class="post-metadata">

**Author:** ![AmauryFaure](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/amauryfaure/32/479_2.png) [@AmauryFaure](https://discuss.ray.io/u/AmauryFaure)\
**Post date:** [February 18, 2021, 8:31pm UTC](https://discuss.ray.io/t/ray-serve-request-object-has-no-attribute-data/931/3 "2021-02-18T20:31:48Z")

</div>

Ah, Many thanks I did not know that,

Indeed the error went away !

Thanks for the help 🙂
