Skip to content

Commit 98623c6

Browse files
authored
Merge pull request #6 from Zipstack/feature/add-doc-splitter-and-generic-clients
remove: test_imports.py file to fix workflow test failure
2 parents 98af5d3 + 9c82603 commit 98623c6

File tree

2 files changed

+40
-153
lines changed

2 files changed

+40
-153
lines changed

src/apihub_client/generic_client.py

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import logging
22
import time
3+
from urllib.parse import parse_qs, urlparse
34

45
import requests
56

@@ -32,6 +33,26 @@ def __init__(
3233
self.base_url = base_url.rstrip("/")
3334
self.headers = {"apikey": self.api_key}
3435

36+
def _extract_execution_id_from_url(self, url: str) -> str | None:
37+
"""
38+
Extract execution_id from a URL's query parameters.
39+
40+
Args:
41+
url: URL containing execution_id parameter
42+
43+
Returns:
44+
str | None: The execution_id if found, None otherwise
45+
"""
46+
try:
47+
parsed_url = urlparse(url)
48+
query_params = parse_qs(parsed_url.query)
49+
execution_ids = query_params.get("execution_id")
50+
if execution_ids:
51+
return execution_ids[0] # Get the first value
52+
except Exception as e:
53+
self.logger.warning("Failed to extract execution_id from URL: %s", e)
54+
return None
55+
3556
def process(
3657
self,
3758
endpoint: str,
@@ -76,6 +97,13 @@ def process(
7697

7798
data = response.json()
7899
execution_id = data.get("execution_id")
100+
101+
# If execution_id is not directly available, try to extract from status_api
102+
if not execution_id:
103+
status_api = data.get("message", {}).get("status_api")
104+
if status_api:
105+
execution_id = self._extract_execution_id_from_url(status_api)
106+
79107
self.logger.info(
80108
"Processing started successfully. Execution ID: %s", execution_id
81109
)
@@ -119,7 +147,17 @@ def get_result(self, endpoint: str, execution_id: str) -> dict:
119147
)
120148
response = requests.get(url, headers=self.headers, params=params)
121149

122-
if response.status_code != 200:
150+
if response.status_code == 422:
151+
# Handle 422 status which may indicate processing in progress
152+
try:
153+
data = response.json()
154+
if "status" in data:
155+
return data
156+
except (ValueError, KeyError):
157+
# JSON parsing failed or status key missing, treat as error
158+
pass
159+
raise ApiHubClientException(response.text, response.status_code)
160+
elif response.status_code != 200:
123161
raise ApiHubClientException(response.text, response.status_code)
124162

125163
return response.json()
@@ -170,7 +208,7 @@ def wait_for_completion(
170208
),
171209
None,
172210
)
173-
elif status in ["PROCESSING", "IN_PROGRESS", "RUNNING"]:
211+
elif status in ["PROCESSING", "IN_PROGRESS", "RUNNING", "EXECUTING"]:
174212
# Continue polling
175213
pass
176214
else:

test/test_imports.py

Lines changed: 0 additions & 151 deletions
This file was deleted.

0 commit comments

Comments
 (0)