History

Nick: fixed the sdks

Nicolas committed 1 year ago

Commit 9ec08d71 parent dd147443 files · +50 −13Browse files

Showing the changes to apps/python-sdk (1 of 3 files). Show all

Unified · Split

apps/python-sdk/firecrawl/firecrawl.py+24−1
@@ -542,6 +542,7 @@ class FirecrawlApp: · 541 unmodified lines
542542 }
543543
544544 try:
545+ # Send the initial extract request
545546 response = self._post_request(
546547 f'{self.api_url}/v1/extract',
547548 request_data,
@@ -550,7 +551,29 @@ class FirecrawlApp: · 2 unmodified lines
550551 if response.status_code == 200:
551552 data = response.json()
552553 if data['success']:
553− return data
554+ job_id = data.get('id')
555+ if not job_id:
556+ raise Exception('Job ID not returned from extract request.')
557+
558+ # Poll for the extract status
559+ while True:
560+ status_response = self._get_request(
561+ f'{self.api_url}/v1/extract/{job_id}',
562+ headers
563+ )
564+ if status_response.status_code == 200:
565+ status_data = status_response.json()
566+ if status_data['status'] == 'completed':
567+ if status_data['success']:
568+ return status_data
569+ else:
570+ raise Exception(f'Failed to extract. Error: {status_data["error"]}')
571+ elif status_data['status'] in ['failed', 'cancelled']:
572+ raise Exception(f'Extract job {status_data["status"]}. Error: {status_data["error"]}')
573+ else:
574+ self._handle_error(status_response, "extract-status")
575+
576+ time.sleep(2) # Polling interval
554577 else:
555578 raise Exception(f'Failed to extract. Error: {data["error"]}')
556579 else: