HTTPCallErrorError(description='401 Client Error: Unauthorized

Project Type: Semantic Segmentation

Operating System & Browser: Windows/ Chrome

Project ID: Recycling Segmentation

Model ID: recycling-segmentation-amso6/28

This error message occurs every single time when I run android studio code which is written by flutter.

HTTPCallErrorError(description='401 Client Error: Unauthorized.

I revoke my api key and I also refresh my render server which is model server website connected by github

I followed the instruction and copied the Hosted Image Inference code but it didn’t work

I don’t know why my gmail account is flagged.

I just wanted to tell my problem.

Admin asked me to give answer so I don’t know how to give grant to admin and I gave team member code but suddenly my account flagged.

I was so frustrated.

I didn’t realized the regulation but it wasn’t intentional.

I sent messages twice time to moderators.

There wasn’t any answer.

I couldn’t replied to admin because I’m already flagged because of my roboflow team member link.

I think admin didn’t realized that I’m flagged.

My workspace email address is different from this account but I’m afraid to tell my email address because I could be flagged again.

I’m the university student and I have to finish this project until this month I mean in summer vacation.

Please help me to find out and solve the problem.

Hi @Minyst!
I deeply apologize for this! To help me troubleshoot, do you mind sharing a code snippet or any further context to help me troubleshoot!

Apologies again for the inconvenience.

from fastapi import FastAPI, UploadFile, File
from fastapi.middleware.cors import CORSMiddleware
from inference_sdk import InferenceHTTPClient
import uvicorn
import os
import tempfile

app = FastAPI()

app.add_middleware(
    CORSMiddleware,
    allow_origins=["*"],
    allow_credentials=True,
    allow_methods=["GET", "POST"],
    allow_headers=["*"],
)

# initialize the client
CLIENT = InferenceHTTPClient(
    api_url="https://serverless.roboflow.com",
    api_key="My own api key"
)

@app.get("/")
async def root():
    return {"message": "Roboflow API Server", "status": "running"}

@app.post("/predict")
async def predict(file: UploadFile = File(...)):
    try:
        # Save uploaded image as temporary file
        with tempfile.NamedTemporaryFile(delete=False, suffix=f".{file.filename.split('.')[-1]}") as temp_file:
            content = await file.read()
            temp_file.write(content)
            temp_file_path = temp_file.name
        
        try:
            # Inference on local image
            result = CLIENT.infer(
                temp_file_path, 
                model_id="recycling-segmentation-amso6/28"  
            )
            return result
            
        except Exception as api_error:
            error_msg = str(api_error)
            if "timeout" in error_msg.lower():
                return {"error": "API server timeout", "status": "failed"}
            elif "connection" in error_msg.lower():
                return {"error": "Network connection failed", "status": "failed"}
            elif "401" in error_msg or "unauthorized" in error_msg.lower():
                return {"error": "API key authentication failed", "status": "failed"}
            elif "404" in error_msg:
                return {"error": "Model not found", "status": "failed"}
            else:
                return {"error": str(api_error), "status": "failed"}
                
        finally:
            # Delete temporary file
            if os.path.exists(temp_file_path):
                os.unlink(temp_file_path)
            
    except Exception as e:
        return {"error": str(e), "status": "failed"}

@app.post("/predict-raw")
async def predict_raw(file: UploadFile = File(...)):
    return await predict(file)

if __name__ == "__main__":
    port = int(os.environ.get("PORT", 8000))
    uvicorn.run("main:app", host="0.0.0.0", port=port, reload=False)

I think you forgot to reply my answer.
Following code is my code snippet.

from fastapi import FastAPI, UploadFile, File
from fastapi.middleware.cors import CORSMiddleware
from inference_sdk import InferenceHTTPClient
import uvicorn
import os
import tempfile

app = FastAPI()

app.add_middleware(
    CORSMiddleware,
    allow_origins=["*"],
    allow_credentials=True,
    allow_methods=["GET", "POST"],
    allow_headers=["*"],
)

# initialize the client
CLIENT = InferenceHTTPClient(
    api_url="https://serverless.roboflow.com",
    api_key="My own api key"
)

@app.get("/")
async def root():
    return {"message": "Roboflow API Server", "status": "running"}

@app.post("/predict")
async def predict(file: UploadFile = File(...)):
    try:
        # Save uploaded image as temporary file
        with tempfile.NamedTemporaryFile(delete=False, suffix=f".{file.filename.split('.')[-1]}") as temp_file:
            content = await file.read()
            temp_file.write(content)
            temp_file_path = temp_file.name
        
        try:
            # Inference on local image
            result = CLIENT.infer(
                temp_file_path, 
                model_id="recycling-segmentation-amso6/28"  
            )
            return result
            
        except Exception as api_error:
            error_msg = str(api_error)
            if "timeout" in error_msg.lower():
                return {"error": "API server timeout", "status": "failed"}
            elif "connection" in error_msg.lower():
                return {"error": "Network connection failed", "status": "failed"}
            elif "401" in error_msg or "unauthorized" in error_msg.lower():
                return {"error": "API key authentication failed", "status": "failed"}
            elif "404" in error_msg:
                return {"error": "Model not found", "status": "failed"}
            else:
                return {"error": str(api_error), "status": "failed"}
                
        finally:
            # Delete temporary file
            if os.path.exists(temp_file_path):
                os.unlink(temp_file_path)
            
    except Exception as e:
        return {"error": str(e), "status": "failed"}

@app.post("/predict-raw")
async def predict_raw(file: UploadFile = File(...)):
    return await predict(file)

if __name__ == "__main__":
    port = int(os.environ.get("PORT", 8000))
    uvicorn.run("main:app", host="0.0.0.0", port=port, reload=False)

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