Hi,
I ran the example code from here
import ray
from ray import serve
import requests
ray.init(num_cpus=4)
client = serve.start()
def say_hello(request):
return "hello " + request.query_params["name"] + "!"
# Form a backend from our function and connect it to an endpoint.
client.create_backend("my_backend", say_hello)
client.create_endpoint("my_endpoint", backend="my_backend", route="/hello")
# Query our endpoint in two different ways: from HTTP and from Python.
print(requests.get("http://127.0.0.1:8000/hello?name=serve").text)
# > hello serve!
print(ray.get(client.get_handle("my_endpoint").remote(name="serve")))
# > hello serve!
Here is the output:
(base) ray@1214b066f43e:/home/ray_server$ python main.py
2021-02-08 07:07:51,247 INFO services.py:1173 -- View the Ray dashboard at http://127.0.0.1:8265
2021-02-08 07:07:51,252 WARNING services.py:1640 -- WARNING: The object store is using /tmp instead of /dev/shm because /dev/shm has only 67108864 bytes available. This may slow down performance! You may be able to free up space by deleting files in /dev/shm or terminating any running plasma_store_server processes. If you are inside a Docker container, you may need to pass an argument with the flag '--shm-size' to 'docker run'.
(pid=2033) 2021-02-08 07:07:52,046 INFO controller.py:346 -- Starting router with name 'qbGXtl:SERVE_CONTROLLER_ACTOR:SERVE_PROXY_ACTOR-node:172.17.0.2-0' on node 'node:172.17.0.2-0' listening on '127.0.0.1:8000'
(pid=2032) INFO: Started server process [2032]
(pid=2033) 2021-02-08 07:07:54,453 INFO controller.py:753 -- Registering route '/hello' to endpoint 'my_endpoint' with methods '['GET']'.
Internal Server Error
2021-02-08 07:07:54,510 INFO router.py:224 -- Endpoint my_endpoint doesn't exist, waiting for registration.
Traceback (most recent call last):
File "main.py", line 24, in <module>
print(ray.get(client.get_handle("my_endpoint").remote(name="serve")))
File "/home/ray/anaconda3/lib/python3.7/site-packages/ray/worker.py", line 1379, in get
raise value.as_instanceof_cause()
ray.exceptions.RayTaskError(AttributeError): ray::RayServeReplica_say_hello.handle_request() (pid=2142, ip=172.17.0.2)
File "/home/ray/anaconda3/lib/python3.7/site-packages/ray/serve/backend_worker.py", line 136, in wrap_to_ray_error
raise exception
File "/home/ray/anaconda3/lib/python3.7/site-packages/ray/serve/backend_worker.py", line 256, in invoke_single
result = await method_to_call(arg)
File "/home/ray/anaconda3/lib/python3.7/site-packages/ray/async_compat.py", line 29, in wrapper
return func(*args, **kwargs)
File "main.py", line 14, in say_hello
return "hello " + request.query_params["name"] + "!"
AttributeError: 'ServeRequest' object has no attribute 'query_params'
(pid=2032) ERROR: Exception in ASGI application
(pid=2032) Traceback (most recent call last):
(pid=2032) File "/home/ray/anaconda3/lib/python3.7/site-packages/uvicorn/protocols/http/h11_impl.py", line 394, in run_asgi
(pid=2032) result = await app(self.scope, self.receive, self.send)
(pid=2032) File "/home/ray/anaconda3/lib/python3.7/site-packages/uvicorn/middleware/proxy_headers.py", line 45, in __call__
(pid=2032) return await self.app(scope, receive, send)
(pid=2032) File "/home/ray/anaconda3/lib/python3.7/site-packages/ray/serve/http_proxy.py", line 124, in __call__
(pid=2032) result = await ref
(pid=2032) ray.exceptions.RayTaskError(AttributeError): ray::RayServeReplica_say_hello.handle_request() (pid=2142, ip=172.17.0.2)
(pid=2032) File "/home/ray/anaconda3/lib/python3.7/site-packages/ray/serve/backend_worker.py", line 136, in wrap_to_ray_error
(pid=2032) raise exception
(pid=2032) File "/home/ray/anaconda3/lib/python3.7/site-packages/ray/serve/backend_worker.py", line 256, in invoke_single
(pid=2032) result = await method_to_call(arg)
(pid=2032) File "/home/ray/anaconda3/lib/python3.7/site-packages/ray/async_compat.py", line 29, in wrapper
(pid=2032) return func(*args, **kwargs)
(pid=2032) File "main.py", line 14, in say_hello
(pid=2032) return "hello " + request.query_params["name"] + "!"
(pid=2032) AttributeError: 'Request' object has no attribute 'query_params'