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

shodan convert stays stuck in an infinite loop when FileNotFoundError

Open Docteur-RS opened this issue 3 years ago • 2 comments

Hey,

I'm using the shodan CLI to convert files from JSON to CSV.
Unfortunately when the file does not exist shodan is stuck in an infinite loop...

$ shodan convert not_existing_file csv --fields "somefields"

-Traceback (most recent call last):
  File "/home/xxxx/miniconda3/bin/shodan", line 33, in <module>
    sys.exit(load_entry_point('shodan==1.24.0', 'console_scripts', 'shodan')())
  File "/home/xxxx/miniconda3/lib/python3.8/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/home/xxxx/miniconda3/lib/python3.8/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/home/xxxx/miniconda3/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/xxxx/miniconda3/lib/python3.8/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/xxxx/miniconda3/lib/python3.8/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/home/xxxx/miniconda3/lib/python3.8/site-packages/shodan-1.24.0-py3.8.egg/shodan/__main__.py", line 127, in convert
  File "/home/xxxx/miniconda3/lib/python3.8/site-packages/shodan-1.24.0-py3.8.egg/shodan/cli/converter/csvc.py", line 59, in process
  File "/home/xxxx/miniconda3/lib/python3.8/site-packages/shodan-1.24.0-py3.8.egg/shodan/helpers.py", line 112, in iterate_files
FileNotFoundError: [Errno 2] No such file or directory: 'not_existing_file '
\
-            # <=== Infinite loop
/           # <==== Pressed CTRL + C
|^CException ignored in: <module 'threading' from '/home/xxxx/miniconda3/lib/python3.8/threading.py'>
Traceback (most recent call last):
  File "/home/xxxx/miniconda3/lib/python3.8/threading.py", line 1388, in _shutdown
    lock.acquire()
KeyboardInterrupt:

It seems stuck on lock.acquire()

It is a real problem for me because I exec the binary with subprocess.run(...). It's not elegant but gets the job done for my purpose.
Well.... It does when the file exists anyway ! If not, it's stuck for ever....

Thx

Docteur-RS avatar Jun 03 '21 17:06 Docteur-RS

@achillean This issue still seems to be present in the CLI.

Are you interested in a PR for this?

rmhowe425 avatar Jul 12 '23 21:07 rmhowe425

Yes, it would be good to properly handle a missing file.

achillean avatar Jul 12 '23 21:07 achillean