|
20 | 20 | from cachetools.func import ttl_cache |
21 | 21 | from requests import Response, Timeout |
22 | 22 | from requests_toolbelt import MultipartEncoder |
| 23 | +from yarl import URL |
23 | 24 |
|
24 | 25 | from inference.core import logger |
25 | 26 | from inference.core.cache import cache |
@@ -290,10 +291,15 @@ def get_roboflow_workspace(api_key: str) -> WorkspaceID: |
290 | 291 | async def get_roboflow_workspace_async(api_key: str) -> WorkspaceID: |
291 | 292 | try: |
292 | 293 | headers = build_roboflow_api_headers() |
| 294 | + full_url = wrap_url( |
| 295 | + _add_params_to_url( |
| 296 | + url=f"{API_BASE_URL}/", |
| 297 | + params=[("api_key", api_key), ("nocache", "true")], |
| 298 | + ) |
| 299 | + ) |
293 | 300 | async with aiohttp.ClientSession() as session: |
294 | 301 | async with session.get( |
295 | | - f"{API_BASE_URL}/", |
296 | | - params={"api_key": api_key, "nocache": "true"}, |
| 302 | + URL(full_url, encoded=True), |
297 | 303 | headers=headers, |
298 | 304 | timeout=ROBOFLOW_API_REQUEST_TIMEOUT, |
299 | 305 | ) as response: |
@@ -332,10 +338,15 @@ async def get_serverless_usage_check_async( |
332 | 338 | ) -> ServerlessUsageCheckResponse: |
333 | 339 | try: |
334 | 340 | headers = build_roboflow_api_headers() |
| 341 | + full_url = wrap_url( |
| 342 | + _add_params_to_url( |
| 343 | + url=f"{API_BASE_URL}/serverless/usage-check", |
| 344 | + params=[("api_key", api_key), ("nocache", "true")], |
| 345 | + ) |
| 346 | + ) |
335 | 347 | async with aiohttp.ClientSession() as session: |
336 | 348 | async with session.get( |
337 | | - f"{API_BASE_URL}/serverless/usage-check", |
338 | | - params={"api_key": api_key, "nocache": "true"}, |
| 349 | + URL(full_url, encoded=True), |
339 | 350 | headers=headers, |
340 | 351 | timeout=ROBOFLOW_API_REQUEST_TIMEOUT, |
341 | 352 | ) as response: |
@@ -389,9 +400,11 @@ def add_custom_metadata( |
389 | 400 | field_name: str, |
390 | 401 | field_value: str, |
391 | 402 | ): |
392 | | - api_url = _add_params_to_url( |
393 | | - url=f"{API_BASE_URL}/{workspace_id}/inference-stats/metadata", |
394 | | - params=[("api_key", api_key), ("nocache", "true")], |
| 403 | + api_url = wrap_url( |
| 404 | + _add_params_to_url( |
| 405 | + url=f"{API_BASE_URL}/{workspace_id}/inference-stats/metadata", |
| 406 | + params=[("api_key", api_key), ("nocache", "true")], |
| 407 | + ) |
395 | 408 | ) |
396 | 409 | response = requests.post( |
397 | 410 | url=api_url, |
@@ -1126,7 +1139,9 @@ def _test_range_request(url: str, timeout: int = 10) -> bool: |
1126 | 1139 | """ |
1127 | 1140 | try: |
1128 | 1141 | headers = {"Range": "bytes=0-0"} |
1129 | | - response = requests.get(url, headers=headers, stream=True, timeout=timeout) |
| 1142 | + response = requests.get( |
| 1143 | + wrap_url(url), headers=headers, stream=True, timeout=timeout |
| 1144 | + ) |
1130 | 1145 | response.close() |
1131 | 1146 | if response.status_code == 206: |
1132 | 1147 | return True |
@@ -1200,9 +1215,11 @@ def send_inference_results_to_model_monitoring( |
1200 | 1215 | workspace_id: WorkspaceID, |
1201 | 1216 | inference_data: dict, |
1202 | 1217 | ): |
1203 | | - api_url = _add_params_to_url( |
1204 | | - url=f"{API_BASE_URL}/{workspace_id}/inference-stats", |
1205 | | - params=[("api_key", api_key)], |
| 1218 | + api_url = wrap_url( |
| 1219 | + _add_params_to_url( |
| 1220 | + url=f"{API_BASE_URL}/{workspace_id}/inference-stats", |
| 1221 | + params=[("api_key", api_key)], |
| 1222 | + ) |
1206 | 1223 | ) |
1207 | 1224 | response = requests.post( |
1208 | 1225 | url=api_url, |
|
0 commit comments