client-python icon indicating copy to clipboard operation
client-python copied to clipboard

[PyCTI] Add retry logic when using withPagination

Open MaxwellDPS opened this issue 3 years ago • 0 comments

Use case

When trying to dump all indicators using the code below, I keep receiving INFO:root:upstream connect error or disconnect/reset before headers. reset reason: connection termination

indicators = api.indicator.list(getAll=True, withPagination=True)
with open('indicators_dump.json', 'w') as fp:
    json.dump(indicators,fp,indent=4)

Current Workaround

Wait till it works, or implementing filters and managing pagination with retries myself

Proposed Solution

add a retry kwarg to to .list() functions or just make it the default behavior

Additional Information

Full trace

Traceback (most recent call last):
  File "<REMOVED>", line 192, in <module>
    indicators = api.indicator.list(getAll=True, withPagination=True)
  File "<REMOVED>/venv/lib/python3.10/site-packages/pycti/entities/opencti_indicator.py", line 248, in list
    result = self.opencti.query(
  File "<REMOVED>/venv/lib/python3.10/site-packages/pycti/api/opencti_api_client.py", line 335, in query
    raise ValueError(r.text)
ValueError: upstream connect error or disconnect/reset before headers. reset reason: connection termination
Killed

If the feature request is approved, would you be willing to submit a PR?

Yes

MaxwellDPS avatar Dec 07 '22 19:12 MaxwellDPS