DevoInc/python-sdk

TypeError: 'NoneType' object is not subscriptable exception in devo client

Closed this issue · 10 comments

Hi! We are using devo-sdk in Cisco Threat Response integration with Devo and encountered TypeError exception in the client code:

response = self._make_request(payload)
try:
first = next(response)
except StopIteration:
first = None
except TypeError:
raise_exception(response)
if self._is_correct_response(first):

Here if first is equal to None and then it's passed to _is_correct_response it tries to be sliced and unhandled TypeError occurs

@staticmethod
def _is_correct_response(line):
try:
if isinstance(line, bytes):
line = line.decode("utf-8")
if "error" in line[:15].lower():
return False
return True
except ValueError:
return False

Hello @oshynk. Thanks for submitting the issue. I think I understand the problem here. Probably adding a check in the first if as a short-circuit might be the solution, but still, could you please attach here a Minimal Reproducible Example?

Please find the example below:

from devo.api import Client, ClientConfig, JSON_SIMPLE

auth = {
    "key": "your_key",
    "secret": "your_secret"
}

address = "apiv2-us.devo.com"
retries = 2
timeout = 25
config = ClientConfig(response="json/simple",
                      processor=JSON_SIMPLE,
                      stream=True)
client = Client(auth=auth, address=address, retries=retries, config=config,
                timeout=timeout)

query = "from all.data where toktains(message, '8.8.8.8')"
dates = {
    "from": "now()-30*day()",
    "to": "now()"
}
limit = 101
response = client.query(query=query, dates=dates, limit=limit)

if __name__ == "__main__":
    [data for data in response]

From what I could find, it seems like this error happens whenever the query returns no results. I believe that the best option to solve this is to replace this line

first = None
with a return None.

Hi, @pavel-razgovorov!
Are there any approximate times when this issue fix will be released?

Hi @mstoro,

This is the last bug I want to fix before uploading a new version, so hopefully once I get the linked PR merged I will start dealing with PyPI's uploads. Please note that the reason we are going slow at these moments is that the previous "main developer" does not maintain this project anymore and hence I still need some time to adapt.

PS: I probably will deploy the next release in https://test.pypi.org/ before doing it in the actual PyPI index. Is it OK for you to let me know whenever this new version is uploaded so you can test it from your end to make sure the bug has been corrected, please?

Got it, thanks!

Yeap, that won't be a problem, you can reach me when release would be on test index.

Hi @mstoro (and @oshynk?),

We finally released the 3.5.0 version in the Test PyPI index. Could you please give it a try and confirm that this bug has been fixed, please? In case it looks OK, we will release the version in the official index soon.

Thanks in advance! And sorry for the huge delay 🤯

Hi @pavel-razgovorov,

Thanks a lot! I'll try it in the next couple of days and let you know.

Hi @pavel-razgovorov,

I had a chance to try it out, and the error doesn't appear anymore.
We look forward to its release on the official index🙂
Thanks again!

Perfect @mstoro! The 3.5.0 has been released. Check it out in https://pypi.org/project/devo-sdk/3.5.0/

Glad the issue is solved! 🙌🏻