codecraftai-restclient-base 1.2.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,666 @@
1
+
2
+ """
3
+ .. module:: restclientbase
4
+ :platform: Darwin, Linux, Unix, Windows
5
+ :synopsis: restclientbase module.
6
+
7
+ .. moduleauthor:: Myron Walker <myron.walker@gmail.com>
8
+ """
9
+
10
+
11
+ __author__ = "Myron Walker"
12
+ __copyright__ = "Copyright 2025, Code Craft AI LLC"
13
+ __credits__ = []
14
+
15
+
16
+ from typing import Dict, List, Optional, Union
17
+
18
+ import logging
19
+ import os
20
+ import time
21
+
22
+
23
+
24
+ from base64 import b64encode
25
+ from http import HTTPStatus
26
+
27
+ from requests import Session, Response, Request
28
+
29
+ from ccai.errors.exceptions import HttpForbiddenError
30
+ from ccai.errors.raising import format_http_error_message, raise_for_http_status
31
+
32
+ from ccai.credentials.basecredential import BaseCredential
33
+ from ccai.credentials.basiccredential import BasicCredential
34
+
35
+ from ccai.restclient.base.aspectsrest import (
36
+ ActionPattern, AspectsRest, LoggingPattern, DEFAULT_REST_ASPECTS
37
+ )
38
+
39
+
40
+ class RestClientBase:
41
+ """
42
+ The :class:`RestClientBase` object is a generic REST client base object that can be inherited from
43
+ in order to implement a REST client that utilizes 'aspects' based APIs
44
+ """
45
+
46
+ AUTH_LEAF = ""
47
+
48
+ # This code is for use with REST clients that can be used in both a production and test environment.
49
+ # we must be able to make calls with SSL certificate verification turned off as some test environments
50
+ # utilized self signed certificates. Allowing the client to make calls with verify turned off is not a bug
51
+ # its a feature.
52
+ VERIFY_CERTIFICATE = True
53
+
54
+ AUTHENTICATION_FAILURES = (HttpForbiddenError)
55
+
56
+ def __init__(self, host: str, credential: BaseCredential, port: Optional[int] = None, scheme: Optional[str] = "https", headers: Optional[Dict[str, str]] = None, verify_certificate: Optional[bool] = None, aspects: AspectsRest = DEFAULT_REST_ASPECTS):
57
+ """
58
+ Initialize the REST client base.
59
+
60
+ :param host: Hostname for the REST service.
61
+ :param credential: Credential used for authentication.
62
+ :param port: Optional port for the service.
63
+ :param scheme: URL scheme, default is ``https``.
64
+ :param verify_certificate: Optional flag to enable or disable TLS verification.
65
+ :param aspects: Default REST aspects.
66
+
67
+ :returns: None
68
+ """
69
+
70
+ self._host = host
71
+ self._credential = credential
72
+ self._headers = headers
73
+ if self._headers is None:
74
+ self._headers = {}
75
+ if verify_certificate is None:
76
+ self._verify_certificate = self.VERIFY_CERTIFICATE
77
+ else:
78
+ self._verify_certificate = verify_certificate
79
+ self._aspects = aspects
80
+
81
+ self._host_url = f"{scheme}://{self._host}"
82
+ if port is not None:
83
+ self._host_url = f"{self._host_url}:{port}"
84
+
85
+ self._session: Session = None
86
+ self._logger = logging.getLogger(__name__)
87
+ return
88
+
89
+ @property
90
+ def aspects(self):
91
+ """
92
+ Default REST aspects for this client.
93
+
94
+ :returns: The AspectsRest instance supplied at construction time.
95
+ """
96
+ return self._aspects
97
+
98
+ @property
99
+ def credential(self):
100
+ """
101
+ Credential object used for authentication with the REST service.
102
+
103
+ :returns: The credential instance supplied at construction time.
104
+ """
105
+ return self._credential
106
+
107
+ @property
108
+ def headers(self):
109
+ """
110
+ Return the client level default headers that are passed for each API call.
111
+ """
112
+ return self._headers
113
+
114
+ @property
115
+ def host(self):
116
+ """
117
+ Hostname assigned to this REST client.
118
+
119
+ :returns: The host string passed to the constructor.
120
+ """
121
+ return self._host
122
+
123
+
124
+ def authenticate(self):
125
+ """
126
+ The `authenticate` method can be overloaded in order to modify the method of authentication
127
+ for the rest client. The current method of authentication is `Basic` authentication.
128
+ """
129
+
130
+ credential: BasicCredential = self._credential
131
+
132
+ username = credential.username
133
+ password = credential.password
134
+
135
+ authbytes = f"{username}:{password}".encode("utf-8")
136
+ passwd_encoded = b64encode(authbytes).decode("utf-8")
137
+
138
+ headers = {
139
+ "Content-Type": "application/json",
140
+ "Authorization": f"Basic {passwd_encoded}"
141
+ }
142
+
143
+ auth_leaf = self.AUTH_LEAF.rstrip("/")
144
+ auth_url = f"{self._host_url}/{auth_leaf}"
145
+
146
+ session = Session()
147
+ session.verify = self._verify_certificate
148
+
149
+ auth_timeouts = (self._aspects.connection_timeout, self._aspects.inactivity_timeout)
150
+ resp: Response = session.post(url=auth_url, headers=headers, verify=self._verify_certificate, timeout=auth_timeouts)
151
+ if resp.status_code != HTTPStatus.OK:
152
+ errmsg_lines = [
153
+ f"Error attempting to authenticate on url={auth_url}.",
154
+ f"STATUS: {resp.status_code}",
155
+ "RESPONSE:",
156
+ resp.text
157
+ ]
158
+ errmsg = os.linesep.join(errmsg_lines)
159
+ raise HttpForbiddenError(errmsg)
160
+
161
+ self._session = session
162
+
163
+ return
164
+
165
+ def perform_call(self, *, leaf: str, method: str, params: Union[Dict[str, str], None], body: Union[Dict[str, str], None],
166
+ exp_status: Union[int, List[int]], headers: Optional[Dict[str, str]] = None,
167
+ context_msg: Optional[str] = None, aspects: Union[AspectsRest, None]) -> Response:
168
+ """
169
+ Perform a REST call using the specified execution aspects.
170
+
171
+ :param leaf: API leaf path.
172
+ :param method: HTTP method name.
173
+ :param params: Optional query parameters.
174
+ :param body: Optional request body.
175
+ :param exp_status: Expected HTTP status codes.
176
+ :param headers: Optional request headers.
177
+ :param context_msg: Optional context message for logging.
178
+ :param aspects: Aspects controlling call behavior.
179
+
180
+ :returns: The :class:`Response` object for the call.
181
+ """
182
+
183
+ if aspects is None:
184
+ aspects = self._aspects
185
+
186
+ response: Response = None
187
+
188
+ action_pattern = aspects.action_pattern
189
+
190
+ if action_pattern == ActionPattern.SINGLE_CALL:
191
+ response = self._perform_single_call(leaf, method, params, body, exp_status, headers, context_msg, aspects)
192
+ elif action_pattern == ActionPattern.SINGLE_CONNECTED_CALL:
193
+ response = self._perform_single_connected_call(leaf, method, params, body, exp_status, headers, context_msg, aspects)
194
+ elif action_pattern == ActionPattern.DO_UNTIL_CONNECTION_FAILURE:
195
+ response = self._perform_call_until_connection_failure(leaf, method, params, body, exp_status, headers, context_msg, aspects)
196
+ elif action_pattern == ActionPattern.DO_UNTIL_SUCCESS:
197
+ response = self._perform_call_until_success(leaf, method, params, body, exp_status, headers, context_msg, aspects)
198
+ elif action_pattern == ActionPattern.DO_WHILE_SUCCESS:
199
+ response = self._perform_call_while_success(leaf, method, params, body, exp_status, headers, context_msg, aspects)
200
+ else:
201
+ errmsg = f"Unsupported action pattern '{action_pattern}'"
202
+ raise RuntimeError(errmsg)
203
+
204
+ return response
205
+
206
+
207
+ def _format_call_url(self, leaf) -> str:
208
+ """
209
+ Compose the full request URL for an API leaf.
210
+
211
+ :param leaf: API path segment to append to the host URL.
212
+
213
+ :returns: Fully qualified URL for the call.
214
+ """
215
+
216
+ call_url = f"{self._host_url}{leaf}"
217
+
218
+ return call_url
219
+
220
+
221
+ def _get_session(self, aspects: AspectsRest) -> Session:
222
+ """
223
+ Retrieve or create the requests session for the given aspects.
224
+
225
+ :param aspects: Execution aspects that may supply a pre-created session.
226
+
227
+ :returns: :class:`Session` object for REST calls.
228
+ """
229
+
230
+ session = None
231
+
232
+ if aspects.session is not None:
233
+ session = aspects.session
234
+ else:
235
+ if self._session is None:
236
+ self.authenticate()
237
+
238
+ session = self._session
239
+
240
+ return session
241
+
242
+
243
+ def _perform_single_call(self, leaf: str, method: str, params: Union[Dict[str, str], None], body: Union[Dict[str, str], None],
244
+ exp_status: Union[int, List[int]], headers: Union[Dict[str, str], None],
245
+ context_msg: Union[str, None], aspects: AspectsRest) -> Response:
246
+ """
247
+ Performs a REST call using a newly authenticated session. Only a single attempt to make the call and provide
248
+ the calling code with the result is made. If the call does not succeed due to authentication failure this could
249
+ be due to a credential timeout. Make a single attempt to reauthenticate and then remake the call.
250
+
251
+ :param leaf: API leaf path for the request.
252
+ :param method: HTTP method to invoke.
253
+ :param params: Query parameters for the request.
254
+ :param body: Request body payload.
255
+ :param exp_status: Expected HTTP status code(s).
256
+ :param headers: Optional HTTP headers.
257
+ :param context_msg: Context message for error reporting.
258
+ :param aspects: Aspects controlling execution behaviour.
259
+
260
+ :returns: The :class:`Response` object from the request.
261
+ """
262
+
263
+ # We need expected status in the form of a collection for our comparison
264
+ if isinstance(exp_status, int):
265
+ exp_status = [exp_status]
266
+
267
+ call_url = self._format_call_url(leaf)
268
+
269
+ logger = self._logger
270
+ if aspects.logger is not None:
271
+ logger = aspects.logger
272
+
273
+ send_timeouts = (aspects.connection_timeout, aspects.inactivity_timeout)
274
+ allowed_error_codes: List[int] = aspects.allowed_error_codes
275
+ allowed_connection_exceptions: List[BaseException] = aspects.allowed_connection_exceptions
276
+
277
+ auth_retry = False
278
+ while True:
279
+
280
+ try:
281
+ session: Session = self._get_session(aspects)
282
+
283
+
284
+ req = Request(method=method, url=call_url, headers=headers, params=params, json=body)
285
+ prepared_req = session.prepare_request(req)
286
+
287
+ resp :Response = session.send(prepared_req, timeout=send_timeouts, verify=self._verify_certificate)
288
+
289
+ except self.AUTHENTICATION_FAILURES as autherr:
290
+ if not auth_retry:
291
+ auth_retry = True
292
+ self._session = None
293
+ else:
294
+ raise # we only make a single attempt to authenticate, bubble any additional failures
295
+
296
+ else:
297
+ break
298
+
299
+ found_status = resp.status_code
300
+ if found_status not in exp_status:
301
+ resp_content = resp.content
302
+
303
+ errmsg = format_http_error_message(found_status, resp_content, call_url, context=context_msg)
304
+ logger.error(errmsg)
305
+
306
+ raise_for_http_status(found_status, resp_content, call_url, context=context_msg)
307
+
308
+ return resp
309
+
310
+
311
+ def _perform_single_connected_call(self, leaf: str, method: str, params: Union[Dict[str, str], None], body: Union[Dict[str, str], None],
312
+ exp_status: Union[int, List[int]], headers: Union[Dict[str, str], None],
313
+ context_msg: Union[str, None], aspects: AspectsRest) -> Response:
314
+ """
315
+ Perform a single call using an existing connection. This call will utilize aspect parameter such as connection timeout in its attempt
316
+ to connect and only gives up if a constraint is exceeded. Once it make a connection it makes a single attempt to perform the call on
317
+ the API and if the call fails, it does not retry.
318
+
319
+ :param leaf: API leaf path to call.
320
+ :param method: HTTP method to use.
321
+ :param params: Query parameters for the call.
322
+ :param body: Body payload for the call.
323
+ :param exp_status: Expected HTTP status code(s).
324
+ :param headers: Optional HTTP headers.
325
+ :param context_msg: Context message for error reporting.
326
+ :param aspects: REST aspects controlling the call.
327
+
328
+ :returns: Response returned from the request.
329
+ """
330
+
331
+ call_url = self._format_call_url(leaf)
332
+
333
+ logger = self._logger
334
+ if aspects.logger is not None:
335
+ logger = aspects.logger
336
+
337
+ send_timeouts = (aspects.connection_timeout, aspects.inactivity_timeout)
338
+ completion_timeout: float = aspects.completion_timeout
339
+ completion_interval: float = aspects.completion_interval
340
+ monitor_delay: float = aspects.monitor_delay
341
+ logging_pattern: LoggingPattern = aspects.logging_pattern
342
+ retry_logging_interval: int = aspects.retry_logging_interval
343
+ allowed_error_codes: List[int] = aspects.allowed_error_codes
344
+ allowed_connection_exceptions: List[BaseException] = aspects.allowed_connection_exceptions
345
+ must_connect: bool = aspects.must_connect
346
+
347
+ # Attempt to establish a connection and make a single call. We will
348
+ # retry connecting until either a connection is made or the completion
349
+ # timeout is exceeded. Once connected, the call is executed only once.
350
+ start_time = time.time()
351
+ attempt = 0
352
+ auth_retry = False
353
+ while True:
354
+
355
+ try:
356
+ session: Session = self._get_session(aspects)
357
+
358
+ req = Request(method=method, url=call_url, headers=headers,
359
+ params=params, json=body)
360
+ prepared_req = session.prepare_request(req)
361
+
362
+ resp: Response = session.send(
363
+ prepared_req, timeout=send_timeouts,
364
+ verify=self._verify_certificate
365
+ )
366
+
367
+ except self.AUTHENTICATION_FAILURES:
368
+ if not auth_retry:
369
+ auth_retry = True
370
+ self._session = None
371
+ continue
372
+ raise
373
+ except Exception as exc: # Connection failure
374
+ if attempt % retry_logging_interval == 0:
375
+ dbg_msg = (
376
+ f"Connection attempt {attempt + 1} failed: {exc}"
377
+ )
378
+ logger.debug(dbg_msg)
379
+
380
+ if time.time() - start_time >= completion_timeout:
381
+ raise TimeoutError(
382
+ f"Timeout attempting call on url={call_url}"
383
+ ) from exc
384
+
385
+ time.sleep(completion_interval)
386
+ attempt += 1
387
+ continue
388
+
389
+ else:
390
+ break
391
+
392
+ found_status = resp.status_code
393
+ if isinstance(exp_status, int):
394
+ exp_list = [exp_status]
395
+ else:
396
+ exp_list = exp_status
397
+
398
+ if found_status not in exp_list:
399
+ resp_content = resp.content
400
+ errmsg = format_http_error_message(
401
+ found_status, resp_content, call_url, context=context_msg
402
+ )
403
+ logger.error(errmsg)
404
+ raise_for_http_status(
405
+ found_status, resp_content, call_url, context=context_msg
406
+ )
407
+
408
+ return resp
409
+
410
+
411
+ def _perform_call_until_connection_failure(self, leaf: str, method: str, params: Union[Dict[str, str], None], body: Union[Dict[str, str], None],
412
+ exp_status: Union[int, List[int]], headers: Union[Dict[str, str], None],
413
+ context_msg: Union[str, None], aspects: AspectsRest) -> Response:
414
+ """
415
+ Perform repeated calls until the connection fails by exceeding a constraint or until a completion timeout is reached. If there is no connection
416
+ failure prior to the completion timeout. It will raise a TimeoutError
417
+
418
+ :returns: The last response obtained before failure.
419
+ """
420
+
421
+ call_url = self._format_call_url(leaf)
422
+
423
+ logger = self._logger
424
+ if aspects.logger is not None:
425
+ logger = aspects.logger
426
+
427
+ send_timeouts = (aspects.connection_timeout, aspects.inactivity_timeout)
428
+ completion_timeout: float = aspects.completion_timeout
429
+ completion_interval: float = aspects.completion_interval
430
+ monitor_delay: float = aspects.monitor_delay
431
+ logging_pattern: LoggingPattern = aspects.logging_pattern
432
+ retry_logging_interval: int = aspects.retry_logging_interval
433
+ allowed_error_codes: List[int] = aspects.allowed_error_codes
434
+ allowed_connection_exceptions: List[BaseException] = aspects.allowed_connection_exceptions
435
+ must_connect: bool = aspects.must_connect
436
+
437
+ # Repeatedly perform the call until we hit a connection failure or the
438
+ # completion timeout expires.
439
+ start_time = time.time()
440
+ attempt = 0
441
+ last_resp: Response = None
442
+ auth_retry = False
443
+
444
+ while True:
445
+ try:
446
+ session: Session = self._get_session(aspects)
447
+
448
+ req = Request(method=method, url=call_url, headers=headers,
449
+ params=params, json=body)
450
+ prepared_req = session.prepare_request(req)
451
+
452
+ resp: Response = session.send(
453
+ prepared_req, timeout=send_timeouts,
454
+ verify=self._verify_certificate
455
+ )
456
+ last_resp = resp
457
+
458
+ except self.AUTHENTICATION_FAILURES:
459
+ if not auth_retry:
460
+ auth_retry = True
461
+ self._session = None
462
+ continue
463
+ break
464
+ except Exception as exc:
465
+ # Any exception is treated as a connection failure
466
+ if attempt % retry_logging_interval == 0:
467
+ dbg_msg = (
468
+ f"Connection failure after {attempt + 1} attempts: {exc}"
469
+ )
470
+ logger.debug(dbg_msg)
471
+ break
472
+
473
+ if time.time() - start_time >= completion_timeout:
474
+ raise TimeoutError(
475
+ f"Timeout waiting for connection failure on url={call_url}"
476
+ )
477
+
478
+ time.sleep(completion_interval)
479
+ attempt += 1
480
+
481
+ return last_resp
482
+
483
+
484
+ def _perform_call_until_success(self, leaf: str, method: str, params: Union[Dict[str, str], None], body: Union[Dict[str, str], None],
485
+ exp_status: Union[int, List[int]], headers: Union[Dict[str, str], None],
486
+ context_msg: Union[str, None], aspects: AspectsRest) -> Response:
487
+ """
488
+ Perform repeated calls until one succeeds.
489
+
490
+ :returns: The successful response object.
491
+ """
492
+
493
+ call_url = self._format_call_url(leaf)
494
+
495
+ logger = self._logger
496
+ if aspects.logger is not None:
497
+ logger = aspects.logger
498
+
499
+ send_timeouts = (aspects.connection_timeout, aspects.inactivity_timeout)
500
+ completion_timeout: float = aspects.completion_timeout
501
+ completion_interval: float = aspects.completion_interval
502
+ monitor_delay: float = aspects.monitor_delay
503
+ logging_pattern: LoggingPattern = aspects.logging_pattern
504
+ retry_logging_interval: int = aspects.retry_logging_interval
505
+ allowed_error_codes: List[int] = aspects.allowed_error_codes
506
+ allowed_connection_exceptions: List[BaseException] = aspects.allowed_connection_exceptions
507
+ must_connect: bool = aspects.must_connect
508
+
509
+ # Loop until we obtain a successful response or a timeout occurs.
510
+ start_time = time.time()
511
+ attempt = 0
512
+ auth_retry = False
513
+
514
+ while True:
515
+ try:
516
+ session: Session = self._get_session(aspects)
517
+
518
+ req = Request(method=method, url=call_url, headers=headers,
519
+ params=params, json=body)
520
+ prepared_req = session.prepare_request(req)
521
+
522
+ resp: Response = session.send(
523
+ prepared_req, timeout=send_timeouts,
524
+ verify=self._verify_certificate
525
+ )
526
+
527
+ except self.AUTHENTICATION_FAILURES:
528
+ if not auth_retry:
529
+ auth_retry = True
530
+ self._session = None
531
+ continue
532
+ if must_connect:
533
+ raise
534
+ resp = None
535
+ except Exception as exc:
536
+ if must_connect:
537
+ raise
538
+ resp = None
539
+ if attempt % retry_logging_interval == 0:
540
+ logger.debug(
541
+ f"Call attempt {attempt + 1} failed: {exc}"
542
+ )
543
+
544
+ else:
545
+ found_status = resp.status_code
546
+ if isinstance(exp_status, int):
547
+ exp_list = [exp_status]
548
+ else:
549
+ exp_list = exp_status
550
+
551
+ if found_status in exp_list:
552
+ return resp
553
+
554
+ if allowed_error_codes and found_status in allowed_error_codes:
555
+ resp = None
556
+ else:
557
+ resp_content = resp.content
558
+ errmsg = format_http_error_message(
559
+ found_status, resp_content, call_url, context=context_msg
560
+ )
561
+ logger.error(errmsg)
562
+ raise_for_http_status(
563
+ found_status, resp_content, call_url, context=context_msg
564
+ )
565
+
566
+ if time.time() - start_time >= completion_timeout:
567
+ raise TimeoutError(
568
+ f"Timeout waiting for successful call on url={call_url}"
569
+ )
570
+
571
+ time.sleep(completion_interval)
572
+ attempt += 1
573
+
574
+
575
+
576
+ def _perform_call_while_success(self, leaf: str, method: str, params: Union[Dict[str, str], None], body: Union[Dict[str, str], None],
577
+ exp_status: Union[int, List[int]], headers: Union[Dict[str, str], None],
578
+ context_msg: Union[str, None], aspects: AspectsRest) -> Response:
579
+ """
580
+ Continue performing calls while each one succeeds.
581
+
582
+ :returns: The last response object received.
583
+ """
584
+
585
+ call_url = self._format_call_url(leaf)
586
+
587
+ logger = self._logger
588
+ if aspects.logger is not None:
589
+ logger = aspects.logger
590
+
591
+ send_timeouts = (aspects.connection_timeout, aspects.inactivity_timeout)
592
+ completion_timeout: float = aspects.completion_timeout
593
+ completion_interval: float = aspects.completion_interval
594
+ monitor_delay: float = aspects.monitor_delay
595
+ logging_pattern: LoggingPattern = aspects.logging_pattern
596
+ retry_logging_interval: int = aspects.retry_logging_interval
597
+ allowed_error_codes: List[int] = aspects.allowed_error_codes
598
+ allowed_connection_exceptions: List[BaseException] = aspects.allowed_connection_exceptions
599
+ must_connect: bool = aspects.must_connect
600
+
601
+ # Continue making calls while each call succeeds. Stop when a call
602
+ # fails or when the completion timeout is reached.
603
+ start_time = time.time()
604
+ attempt = 0
605
+ last_resp: Response = None
606
+ auth_retry = False
607
+
608
+ while True:
609
+ try:
610
+ session: Session = self._get_session(aspects)
611
+
612
+ req = Request(method=method, url=call_url, headers=headers,
613
+ params=params, json=body)
614
+ prepared_req = session.prepare_request(req)
615
+
616
+ resp: Response = session.send(
617
+ prepared_req, timeout=send_timeouts,
618
+ verify=self._verify_certificate
619
+ )
620
+
621
+ except self.AUTHENTICATION_FAILURES:
622
+ if not auth_retry:
623
+ auth_retry = True
624
+ self._session = None
625
+ continue
626
+ if must_connect:
627
+ raise
628
+ break
629
+ except Exception as exc:
630
+ if must_connect:
631
+ raise
632
+ if attempt % retry_logging_interval == 0:
633
+ logger.debug(
634
+ f"Call failed after {attempt + 1} attempts: {exc}"
635
+ )
636
+ break
637
+ else:
638
+ last_resp = resp
639
+ found_status = resp.status_code
640
+ if isinstance(exp_status, int):
641
+ exp_list = [exp_status]
642
+ else:
643
+ exp_list = exp_status
644
+
645
+ if found_status not in exp_list:
646
+ if allowed_error_codes and found_status in allowed_error_codes:
647
+ break
648
+ resp_content = resp.content
649
+ errmsg = format_http_error_message(
650
+ found_status, resp_content, call_url, context=context_msg
651
+ )
652
+ logger.error(errmsg)
653
+ raise_for_http_status(
654
+ found_status, resp_content, call_url, context=context_msg
655
+ )
656
+
657
+ if time.time() - start_time >= completion_timeout:
658
+ raise TimeoutError(
659
+ f"Timeout waiting for call failure on url={call_url}"
660
+ )
661
+
662
+ time.sleep(completion_interval)
663
+ attempt += 1
664
+
665
+ return last_resp
666
+