I just deployed my app to Hugging Face Spaces, and I’m encountering an issue with internet connectivity. Here’s the snippet of code that’s throwing an error:

response = requests.get("https://api.openai.com/v1/models", timeout=5)

if response.status_code == 200:

st.success("Internet connectivity is working.")

else:

st.error(f"Internet not reachable: {response.status_code} - {response.reason}")

While testing this on the Hugging Face Space, I get the following error:

Internet not reachable: 401 - Unauthorized

This same code works perfectly fine locally on my machine, which makes me wonder if the free tier of Hugging Face Spaces blocks internet access or if there’s something else I’m missing.

The error is an api authorization error, not related to internet…

Seems to be an API key issue.

How did you setup the API key?

Ashish Singh You are absolutely right. The API key I added had some line characters and white spaces when I copied it from my local .env file. I generated a new key from the OpenAI portal, and it worked perfectly on Hugging Face. Thanks a lot for pointing that out!

Post a comment