-
-
Notifications
You must be signed in to change notification settings - Fork 307
Description
Bug Description
From Discord
I'm creating an app using Robyn Framework but keeps encountering CORS issue when streaming. I'm currently using ALLOW_CORS on my main.py but keeps encountering this issue:
Access to fetch at 'http://localhost:8087/scraping/crawl' from origin 'http://localhost:8910' has been blocked by CORS policy: The 'Access-Control-Allow-Origin' header contains multiple values '*, http://localhost:8910', but only one is allowed. Have the server send the header with a valid value. which is weird since there is no one calling * for Access-Control-Allow-Origin . I checked my other API endpoins and it's only throwing only 1 Access-Control-Allow-Origin but for my crawl API endpoint that is currently using SSEResponse it's thorwing 2 Access-Control-Allow-Origin
Steps to Reproduce
I'm using CORS on my main.py just like this:
app = Robyn(
file_object=__file__,
openapi=OpenAPI(
info=OpenAPIInfo(
title="Gen AI Scraper",
description="Fanta Scraper but using generative AI",
version="0.1.0",
components=Components(),
)
),
)
ALLOW_CORS(app, origins=[REDWOOD_URL])
Then on my API Endpoint
@scraping_router.post("/crawl", openapi_name="Crawlee Request with SSE")
async def crawlee_request(request: Request):
try:
if not hasattr(request, "user"):
async def error_stream():
yield SSEMessage(
event="error",
data=json.dumps({
"error": "Authentication context missing",
"status_code": 500
})
)
return SSEResponse(error_stream())
try:
body = request.json()
crawl_request = CrawlRequest(**body)
except Exception as e:
return Response(
status_code=400,
headers={},
description=json.dumps({"detail": f"Invalid request body: {str(e)}"})
)
url = crawl_request.url
return SSEResponse(start_crawling_stream_sse(url))
except Exception as e:
logger.info(f":x: Error in crawl_stream: {str(e)}")
return Response(
status_code=500,
headers={},
description=json.dumps({"detail": str(e)})
)
Your operating system
None
Your Python version (python --version
)
None
Your Robyn version
None
Additional Info
No response