Skip to content

Supercharge your AI agents with data from the web and beyond. Building the library for superintelligence. 🔥

fix(python-sdk): handle async v1 batch scrape response dict

Yufeng He2f968913184e
diff --git a/apps/python-sdk/firecrawl/v1/client.py b/apps/python-sdk/firecrawl/v1/client.py
index 857e61567..df4236af7 100644
--- a/apps/python-sdk/firecrawl/v1/client.py
+++ b/apps/python-sdk/firecrawl/v1/client.py
@@ -4015,13 +4015,10 @@ class AsyncV1FirecrawlApp(V1FirecrawlApp):
headers
)
- if response.get('status_code') == 200:
- try:
- return V1BatchScrapeResponse(**response.json())
- except:
- raise Exception(f'Failed to parse Firecrawl response as JSON.')
- else:
- await self._handle_error(response, 'start batch scrape job')
+ if response.get('success'):
+ return V1BatchScrapeResponse(**response)
+
+ await self._handle_error(response, 'start batch scrape job')
async def crawl_url(
self,
diff --git a/apps/python-sdk/tests/test_v1_async_batch_scrape.py b/apps/python-sdk/tests/test_v1_async_batch_scrape.py
new file mode 100644
index 000000000..f5ee269a5
--- /dev/null
+++ b/apps/python-sdk/tests/test_v1_async_batch_scrape.py
@@ -0,0 +1,29 @@
+import asyncio
+
+from firecrawl.v1.client import AsyncV1FirecrawlApp
+
+
+def test_async_batch_scrape_urls_accepts_parsed_json_response(monkeypatch):
+ app = AsyncV1FirecrawlApp(api_key="fc-test", api_url="http://localhost:9")
+ calls = []
+
+ async def fake_post_request(url, data, headers):
+ calls.append((url, data, headers))
+ return {
+ "success": True,
+ "id": "batch-123",
+ "url": "http://localhost:9/v1/batch/scrape/batch-123",
+ }
+
+ async def fail_handle_error(response, action):
+ raise AssertionError(f"unexpected error path: {action} {response!r}")
+
+ monkeypatch.setattr(app, "_async_post_request", fake_post_request)
+ monkeypatch.setattr(app, "_handle_error", fail_handle_error)
+
+ result = asyncio.run(app.async_batch_scrape_urls(["https://example.com"]))
+
+ assert result.success is True
+ assert result.id == "batch-123"
+ assert result.url == "http://localhost:9/v1/batch/scrape/batch-123"
+ assert calls[0][1]["urls"] == ["https://example.com"]