# API endpoint doesn't work

**URL:** <https://discuss.huggingface.co/t/api-endpoint-doesnt-work/44258>\
**Category:** 🔒 Gradio\
**Created:** [June 23, 2023, 3:33am UTC](https://discuss.huggingface.co/t/api-endpoint-doesnt-work/44258 "2023-06-23T03:33:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![JingpuShi](https://avatars.discourse-cdn.com/v4/letter/j/dec6dc/32.png) [@JingpuShi](https://discuss.huggingface.co/u/JingpuShi)\
**Post date:** [June 23, 2023, 3:33am UTC](https://discuss.huggingface.co/t/api-endpoint-doesnt-work/44258/1 "2023-06-23T03:33:07Z")

</div>

I tried to call the API of a space from a different space. This is the recommended use:

from gradio\_client import Client

client = Client(“[https://my-private-space.hf.space/](https://my-private-space.hf.space/)”)  
result = client.predict(  
“Howdy!”, # str in ‘parameter\_2’ Textbox component  
“null”, # str (filepath to JSON file) in ‘parameter\_1’ Chatbot component  
fn\_index=2  
)  
print(result)

So I called as follows:

\_, \_ = client.predict(‘ok’, ‘ok’, fn\_index=2)

But got an error: Any ideas?

Traceback (most recent call last):  
File “/home/user/.local/lib/python3.9/site-packages/gradio/routes.py”, line 437, in run\_predict  
output = await app.get\_blocks().process\_api(  
File “/home/user/.local/lib/python3.9/site-packages/gradio/blocks.py”, line 1352, in process\_api  
result = await self.call\_function(  
File “/home/user/.local/lib/python3.9/site-packages/gradio/blocks.py”, line 1077, in call\_function  
prediction = await anyio.to\_thread.run\_sync(  
File “/home/user/.local/lib/python3.9/site-packages/anyio/to\_thread.py”, line 33, in run\_sync  
return await get\_asynclib().run\_sync\_in\_worker\_thread(  
File “/home/user/.local/lib/python3.9/site-packages/anyio/\_backends/\_asyncio.py”, line 877, in run\_sync\_in\_worker\_thread  
return await future  
File “/home/user/.local/lib/python3.9/site-packages/anyio/\_backends/\_asyncio.py”, line 807, in run  
result = context.run(func, \*args)  
File “/home/user/app/app.py”, line 34, in respond  
chat\_history = ask\_question(message, chat\_history)  
File “/home/user/app/app.py”, line 10, in ask\_question  
\_, \_ = client.predict(“ok”, “ok”, fn\_index=2)  
File “/home/user/.local/lib/python3.9/site-packages/gradio\_client/client.py”, line 272, in predict  
return self.submit(\*args, api\_name=api\_name, fn\_index=fn\_index).result()  
File “/home/user/.local/lib/python3.9/site-packages/gradio\_client/client.py”, line 973, in result  
return super().result(timeout=timeout)  
File “/usr/local/lib/python3.9/concurrent/futures/\_base.py”, line 446, in result  
return self.\_\_get\_result()  
File “/usr/local/lib/python3.9/concurrent/futures/\_base.py”, line 391, in \_\_get\_result  
raise self.\_exception  
File “/usr/local/lib/python3.9/concurrent/futures/thread.py”, line 58, in run  
result = self.fn(\*self.args, \*\*self.kwargs)  
File “/home/user/.local/lib/python3.9/site-packages/gradio\_client/client.py”, line 629, in \_inner  
data = self.serialize(\*data)  
File “/home/user/.local/lib/python3.9/site-packages/gradio\_client/client.py”, line 799, in serialize  
o = tuple([s.serialize(d) for s, d in zip(self.serializers, data)])  
File “/home/user/.local/lib/python3.9/site-packages/gradio\_client/client.py”, line 799, in   
o = tuple([s.serialize(d) for s, d in zip(self.serializers, data)])  
File “/home/user/.local/lib/python3.9/site-packages/gradio\_client/serializing.py”, line 420, in serialize  
return utils.file\_to\_json(Path(load\_dir) / x)  
File “/home/user/.local/lib/python3.9/site-packages/gradio\_client/utils.py”, line 430, in file\_to\_json  
with open(file\_path) as f:  
FileNotFoundError: [Errno 2] No such file or directory: ‘ok’

---

<div class="post-metadata">

**Author:** ![radames](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/radames/32/28246_2.png) [@radames](https://discuss.huggingface.co/u/radames)\
**Post date:** [June 23, 2023, 4:02am UTC](https://discuss.huggingface.co/t/api-endpoint-doesnt-work/44258/2 "2023-06-23T04:02:44Z")

</div>

hi @JingpuShi ,  
Have you tried passing your hftoken? since it lookes like it’s a private, unpublised Space? you could also try the `serialize` option

```python
client = Client("https://my-private-space.hf.space/",hf_token="hf...", serialize=False)

```

---

<div class="post-metadata">

**Author:** ![JingpuShi](https://avatars.discourse-cdn.com/v4/letter/j/dec6dc/32.png) [@JingpuShi](https://discuss.huggingface.co/u/JingpuShi)\
**Post date:** [June 23, 2023, 6:00am UTC](https://discuss.huggingface.co/t/api-endpoint-doesnt-work/44258/3 "2023-06-23T06:00:51Z")

</div>

serialize=False fixed it. Thanks a lot for your help @radames !!!
