AlienVault-OTX / OTX-Python-SDK

The Python SDK for AlienVault OTX
Other
358 stars 162 forks source link

AttributeError: 'NoneType' object has no attribute 'read' #44

Closed maitray16 closed 5 years ago

maitray16 commented 5 years ago

When looping through IP's using the otx.get_indicator_details_full function, I get an error - AttributeError: 'NoneType' object has no attribute 'read'.

Traceback (most recent call last):

  File "/usr/local/lib/python3.6/site-packages/celery/app/trace.py", line 375, in trace_task

    R = retval = fun(*args, **kwargs)

  File "/usr/local/lib/python3.6/site-packages/celery/app/trace.py", line 632, in __protected_call__

    return self.run(*args, **kwargs)

  File "/usr/src/app/app/tasks.py", line 32, in process_ips

    document = IPHandler().process(ip)

  File "/usr/src/app/app/engine/ip_handler.py", line 39, in process

    OTX_response = self.get_OTX_data(ip)

  File "/usr/src/app/app/engine/ip_handler.py", line 15, in get_OTX_data

    otx_data = self.otx.get_indicator_details_full(IndicatorTypes.IPv4, ip)

  File "/usr/local/lib/python3.6/site-packages/OTXv2.py", line 492, in get_indicator_details_full

    indicator_dict[section] = self.get(indicator_url)

  File "/usr/local/lib/python3.6/site-packages/OTXv2.py", line 83, in get

    data = response.read().decode('utf-8')

AttributeError: 'NoneType' object has no attribute 'read' 

Using Python Version - 3.6.4

joaquinrinaudo-olx commented 5 years ago

Similar problem on OSX:


print(otx.getall())
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.7/site-packages/OTXv2.py", line 273, in getall
    json_data = self.get(next_page_url)
  File "/usr/local/lib/python3.7/site-packages/OTXv2.py", line 83, in get
    data = response.read().decode('utf-8')
AttributeError: 'NoneType' object has no attribute 'read'
coppolak commented 5 years ago

I am getting the same.

Starting OTX feed download ... Traceback (most recent call last): File "get-otx-iocs.py", line 297, in otx_receiver.get_iocs_last() File "get-otx-iocs.py", line 146, in get_iocs_last self.events = self.otx.getall() File "/usr/lib/python2.7/site-packages/OTXv2.py", line 273, in getall json_data = self.get(next_page_url) File "/usr/lib/python2.7/site-packages/OTXv2.py", line 83, in get data = response.read().decode('utf-8') AttributeError: 'NoneType' object has no attribute 'read'

chrisdoman commented 5 years ago

Hi,

I'm looking into this.

Can you confirm if you're using the latest version from Github, or the slightly older version from pip?

Many thanks,

coppolak commented 5 years ago

Hi,

I'm looking into this.

Can you confirm if you're using the latest version from Github, or the slightly older version from pip?

Many thanks,

Sorry, if this is regarding the cli-example, I also tried that one. Was not getting any errors but nothing was happening when I ran it. Not using python 3.

chrisdoman commented 5 years ago

Thanks coppolak.

We've recently had some large increases in API usage that were impacting performance, and have started limiting requests to getall() without "modified_since" set to one every two hours. Apologies for not documenting that in the SDK.

We're updating the API later today to make that less strict so your script may start working after that.

In the short term, adding modified_since should make the calls work.

For example: print(otx.getall())

Becomes:

three_months_dt = (datetime.datetime.now() - datetime.timedelta(days=1))
print(otx.getall(modified_since=three_months_dt))

In the longer term - we're looking at a few options to do this better and I will update here.

coppolak commented 5 years ago

Thanks coppolak.

We've recently had some large increases in API usage that were impacting performance, and have started limiting requests to getall() without "modified_since" set to one every two hours. Apologies for not documenting that in the SDK.

We're updating the API later today to make that less strict so your script may start working after that.

In the short term, adding modified_since should make the calls work.

For example: print(otx.getall())

Becomes:

three_months_dt = (datetime.datetime.now() - datetime.timedelta(days=1))
print(otx.getall(modified_since=three_months_dt))

In the longer term - we're looking at a few options to do this better and I will update here.

Thank you for letting me know. I tried what you said:

    if args["subscribed"]:
        three_months_dt=(datetime.datetime.now() - datetime.timedelta(days=90))
        print (str(otx.getall(modified_since=three_months_dt)))

And I am still not having any luck. No error, but still nothing happening.

chrisdoman commented 5 years ago

Hi @maitray16 - are you still getting the same error please?

Your issue is slightly different to the other reported here.

chrisdoman commented 5 years ago

Hi @coppolak

Can I confirm the command you're running please? Eg; python cli_example.py -s or python cli_example.py --subscribed

Is your user subscribed to any users?

Thanks,

maitray16 commented 5 years ago

Hey @chrisdoman - Let me test it out. Currently switched to using requests and fetching different sections when needed, seems to be working fine. Will test it out with the original script and let you know.

coppolak commented 5 years ago

Hi @chrisdoman I am now getting the error getall() got an unexpected keyword argument 'modified_since'

maitray16 commented 5 years ago

@chrisdoman I ran it through a list of few 100 IPs, haven't noticed an issue or NoneType errors, seems to be working fine.

chrisdoman commented 5 years ago

Hi @coppolak - try downloading the latest version of the repository and installing it, i.e. python setup.py install

coppolak commented 5 years ago

Hi @chrisdoman I have the latest version

coppolak commented 5 years ago

@chrisdoman the issue has been resolved. However, whenever I run the script with any arugments other than --subscribed, I get error: error:argument -d/--domain:expected one argument. What am I missing?

chrisdoman commented 5 years ago

@coppolak are you providing a domain to check? eg; python cli_example.py --domain google.com

I'll close this ticket as it seems the original issue is fixed, but feel free to open a new one.