I try curl from basic guide, but it throws: 405({ “detail”: “Method Not Allowed”}).
Curl: curl -X POST https://golddany-didefbackend.hf.space/call/predict -s -H “Content-Type: application/json” -d ‘{
“data”: [
“Hello!!”
]}’
| awk -F’"’ ‘{ print $4}’
| read EVENT_ID; curl -N https://golddany-didefbackend.hf.space/call/predict/$EVENT_ID
I can get event_id from first request, but second(../$EVENT_ID) always throws: “Connection broken: InvalidChunkLength(got length b’‘, 0 bytes read)”, InvalidChunkLength(got length b’’, 0 bytes read)
1 Like
Hmm, I think the code is written according to the sample. I don’t know what the problem is…
I’ll try experimenting a little later.
1 Like
It worked for some reason… From the server side, it should be the same thing…
import os, requests
SPACE = "john6666-apitest1.hf.space"
API_NAME = "predict"
HF_TOKEN = os.getenv("HF_TOKEN", None)
base = f"https://{SPACE}"
auth_h = {"Authorization": f"Bearer {HF_TOKEN}", "Content-Type": "application/json"} if HF_TOKEN else {}
r = requests.post(f"{base}/call/{API_NAME}", headers=auth_h, json={"data": ["hi"]}, timeout=30)
r.raise_for_status()
eid = r.json()["event_id"]
with requests.get(f"{base}/call/{API_NAME}/{eid}", headers={"Authorization": f"Bearer {HF_TOKEN}", "Accept": "text/event-stream"}, stream=True, timeout=300) as resp:
for line in resp.iter_lines(decode_unicode=True):
if line:
print(line) # data: [[0.03394877910614014, -0.005614369176328182, -0.0012183655053377151, 0.015974245965480804,...
1 Like
system
Closed
August 12, 2025, 1:32pm
4
This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.