Issue with FlaskAPI in a Private Space After Sleeping Mode

Hey everyone,

I’m facing an issue with my FlaskAPI running in a private Hugging Face Space. I’ve set the space to enter sleeping mode after some time to save resources. However, when I try to wake it up after a few hours by sending a GET/POST request, I get a 404 error.

I suspect this might be related to the spaces-jwt token refreshing periodically. I found this thread discussing JWT expiration settings:
https://discuss.huggingface.co/t/how-to-modify-the-fastapi-jwt-token-expiration-setting-issued-by-huggingface/78593

However, when I try to send the GET request, I get a “Sorry, we can’t find the page you are looking for” error. I’m not sure if my issue is due to an incorrect setup, the token expiration, or something related to the sleeping mode.

My Space: idkash1/Detect_Edits_in_AI-Generated_Text

Would appreciate any insights or advice.
Thanks in advance!

1 Like

Hmm… It works. I think it’s sleeping on its own, but I wonder if it won’t happen unless you explicitly put it into sleep mode.

HF_TOKEN = "hf_my_pro_token"
import requests
headers = {"Authorization": f"Bearer {HF_TOKEN}"}
url = "https://huggingface.co/api/spaces/John6666/gradio-server-test/jwt"
result = requests.get(url, headers=headers).json()
print(result)
# {'token': '...

I couldn’t see it because it was a private space, so I changed it to public and found the token via the API.

1 Like

In my case, the script above worked in Private Space. So, I think it’s possible that there’s something wrong with the state of the Spaces or it’s a server glitch.

A few hours ago, an error was reported on HF Discord for a completely different matter, and it fixed itself. It might be something similar.

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.