fix: Exception in VT module

pull/502/head
Raphaël Vinot 2022-08-25 16:09:30 +02:00
parent dac45e401f
commit 31514b79f9
1 changed files with 10 additions and 3 deletions

View File

@ -1,6 +1,7 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import json import json
import logging
import time import time
from datetime import date from datetime import date
from typing import Any, Dict, Optional from typing import Any, Dict, Optional
@ -9,13 +10,15 @@ import vt # type: ignore
from har2tree import CrawledTree from har2tree import CrawledTree
from vt.error import APIError # type: ignore from vt.error import APIError # type: ignore
from ..default import ConfigError, get_homedir from ..default import ConfigError, get_homedir, get_config
from ..helpers import get_cache_directory from ..helpers import get_cache_directory
class VirusTotal(): class VirusTotal():
def __init__(self, config: Dict[str, Any]): def __init__(self, config: Dict[str, Any]):
self.logger = logging.getLogger(f'{self.__class__.__name__}')
self.logger.setLevel(get_config('generic', 'loglevel'))
if not config.get('apikey'): if not config.get('apikey'):
self.available = False self.available = False
return return
@ -93,6 +96,10 @@ class VirusTotal():
if not self.autosubmit: if not self.autosubmit:
break break
if not scan_requested and e.code == 'NotFoundError': if not scan_requested and e.code == 'NotFoundError':
self.client.scan_url(url) try:
scan_requested = True self.client.scan_url(url)
scan_requested = True
except APIError as e:
self.logger.warning(f'Unable to trigger VirusTotal on {url}: {e}')
break
time.sleep(5) time.sleep(5)