{"record":{"id":"cb896fa93dcc5542","repo":"apache/beam","slug":"could-not-complete-request-requestresponse","errorCode":null,"errorMessage":"could not complete request","messagePattern":"could not complete request","errorType":"exception","errorClass":"UserCodeExecutionException","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/io/requestresponse.py","lineNumber":211,"sourceCode":"  with concurrent.futures.ThreadPoolExecutor() as executor:\n    future = executor.submit(caller, request)\n    try:\n      return future.result(timeout=timeout)\n    except TooManyRequests as e:\n      _LOGGER.info(\n          'request could not be completed. got code %i from the service.',\n          e.code)\n      raise e\n    except concurrent.futures.TimeoutError:\n      if metrics_collector:\n        metrics_collector.timeout_requests.inc(1)\n      raise UserCodeTimeoutException(\n          f'Timeout {timeout} exceeded '\n          f'while completing request: {request}')\n    except RuntimeError:\n      if metrics_collector:\n        metrics_collector.failures.inc(1)\n      raise UserCodeExecutionException('could not complete request')\n\n\nclass ExponentialBackOffRepeater(Repeater):\n  \"\"\"Configure exponential backoff retry strategy.\n\n  It retries for exceptions due to the remote service such as\n  TooManyRequests (HTTP 429), UserCodeTimeoutException, UserCodeQuotaException.\n\n  It utilizes the decorator\n  :func:`apache_beam.utils.retry.with_exponential_backoff`.\n  \"\"\"\n  def __init__(self):\n    pass\n\n  @retry.with_exponential_backoff(\n      num_retries=2, retry_filter=retry_on_exception)\n  def repeat(\n      self,","sourceCodeStart":193,"sourceCodeEnd":229,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/io/requestresponse.py#L193-L229","documentation":"_execute_request converts any RuntimeError raised by the user callable into UserCodeExecutionException with the message 'could not complete request'. It signals that the request could not be executed, separate from HTTP error codes or timeouts.","triggerScenarios":"The user-supplied callable raises RuntimeError during execution in _execute_request; the exception is caught by `except RuntimeError:` and re-wrapped (the failure metric is incremented if a metrics collector is present).","commonSituations":"User code performing requests with requests/httpx raising RuntimeError on connection issues; generic runtime failures inside the custom Caller implementation.","solutions":["Inspect the original exception in the logs/cause to find the root cause inside your Caller implementation.","Fix the user callable so it does not raise RuntimeError (e.g. handle connection errors and raise UserCodeExecutionException with details yourself).","Add retry logic (Repeater) for transient remote service failures.","Add defensive error handling and validation of inputs/connections in the callable."],"exampleFix":"// before\ndef __call__(self, request):\n  return requests.post(self.url, json=request).json()  # may raise RuntimeError\n// after\ndef __call__(self, request):\n  try:\n    return requests.post(self.url, json=request, timeout=10).json()\n  except Exception as e:\n    raise UserCodeExecutionException(f'request failed: {e}') from e","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n  result = do_request(request)\nexcept UserCodeExecutionException as e:\n  logging.error('request failed: %s', e)\n  # inspect root cause via e.__cause__ and retry or dead-letter","preventionTips":["Wrap user callables to raise informative exceptions instead of bare RuntimeError","Validate inputs and connection state before issuing requests","Add retries for transient remote failures"],"tags":["python","apache-beam","http","request-failure"],"backgroundTag":"http-request-failed","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}