nessrest icon indicating copy to clipboard operation
nessrest copied to clipboard

req.text hanging on download_scan->action

Open 0xbcf opened this issue 8 years ago • 0 comments

req.text on line 217 of ness6rest.py was hanging with high CPU usage when calling download_scan and returning a 61MB csv scan.

Here is an example trace when I hit Ctrl-C: ^CTraceback (most recent call last): File "examplescript.py", line 117, in fp.write(scanner.download_scan(export_format=args.format)) File "build/bdist.linux-x86_64/egg/nessrest/ness6rest.py", line 959, in download_scan File "build/bdist.linux-x86_64/egg/nessrest/ness6rest.py", line 217, in action File "/usr/lib/python2.7/site-packages/requests/models.py", line 765, in text encoding = self.apparent_encoding File "/usr/lib/python2.7/site-packages/requests/models.py", line 640, in apparent_encoding return chardet.detect(self.content)['encoding'] File "/usr/lib/python2.7/site-packages/chardet/init.py", line 30, in detect u.feed(aBuf) File "/usr/lib/python2.7/site-packages/chardet/universaldetector.py", line 119, in feed if self._mEscCharSetProber.feed(aBuf) == constants.eFoundIt: File "/usr/lib/python2.7/site-packages/chardet/escprober.py", line 74, in feed codingState = codingSM.next_state(wrap_ord(c)) File "/usr/lib/python2.7/site-packages/chardet/codingstatemachine.py", line 46, in next_state byteCls = self._mModel['classTable'][wrap_ord(c)] File "/usr/lib/python2.7/site-packages/chardet/compat.py", line 31, in wrap_ord if sys.version_info < (3, 0) and isinstance(a, base_str): KeyboardInterrupt

I changed line 217 to read "else:" and it is functional now, but i'm not certain if other features needed the previous logic "elif not req.text:", though it would seem to be mostly implied that it is not req.text if it already failed the first if condition.

The code section now reads: if not download and req.text: self.res = req.json() else: self.res = {}

0xbcf avatar May 03 '17 13:05 0xbcf