VirusTotal / vt-py

The official Python 3 client library for VirusTotal
https://virustotal.github.io/vt-py/
Apache License 2.0
532 stars 121 forks source link

[bug] examples/download_files.py broken for python >= 3.10 #113

Closed tlansec closed 1 year ago

tlansec commented 1 year ago

This example is broken for Python >= 3.10:

https://github.com/VirusTotal/vt-py/blob/master/examples/download_files.py

Results in:

  File "/mnt/hgfs/Work/misc_ti/virustotal/download_util.py", line 85, in main
    queue = asyncio.Queue(loop=loop)
  File "/usr/lib/python3.10/asyncio/queues.py", line 34, in __init__
    super().__init__(loop=loop)
  File "/usr/lib/python3.10/asyncio/mixins.py", line 17, in __init__
    raise TypeError(
TypeError: As of 3.10, the *loop* parameter was removed from Queue() since it is no longer necessary

Needs something like this for python 3.10 or greater:

loop = asyncio.get_event_loop()
    queue = asyncio.Queue()
    for hash in input_file:
        queue.put_nowait(hash.strip())

    worker_tasks = []
    for _ in range(args.workers):
        worker_tasks.append(
            loop.create_task(download_files(queue, args)))

    # Wait until all worker tasks has completed.
    loop.run_until_complete(asyncio.gather(*worker_tasks))
    loop.close()
    if not isinstance(input_file, list):
        input_file.close()