@@ -261,7 +261,10 @@ def send_file_analysis_playbook_request(
261
261
262
262
if runtime_configuration :
263
263
data ["runtime_configuration" ] = json .dumps (runtime_configuration )
264
- files = {"file" : (filename , binary )}
264
+ # `files` is wanted to be different from the other
265
+ # /api/analyze_file endpoint
266
+ # because the server is using different serializers
267
+ files = {"files" : (filename , binary )}
265
268
answer = self .__send_analysis_request (
266
269
data = data , files = files , playbook_mode = True
267
270
)
@@ -472,6 +475,7 @@ def __send_analysis_request(self, data=None, files=None, playbook_mode=False):
472
475
Internal use only.
473
476
"""
474
477
response = None
478
+ answer = {}
475
479
if files is None :
476
480
url = self .instance + "/api/analyze_observable"
477
481
if playbook_mode :
@@ -495,7 +499,9 @@ def __send_analysis_request(self, data=None, files=None, playbook_mode=False):
495
499
answer = response .json ()
496
500
if playbook_mode :
497
501
# right now, we are only supporting single input result
498
- answer = answer .get ("results" , [])[0 ]
502
+ answers = answer .get ("results" , [])
503
+ if answers :
504
+ answer = answers [0 ]
499
505
500
506
warnings = answer .get ("warnings" , [])
501
507
if self .cli :
@@ -505,11 +511,12 @@ def __send_analysis_request(self, data=None, files=None, playbook_mode=False):
505
511
[i yellow]{ warnings if warnings else None } [/]
506
512
"""
507
513
else :
508
- info_log = f"""New Job running..
509
- ID: { answer ['job_id' ]} | Status: { answer ['status' ]} .
510
- Got { len (warnings )} warnings:
511
- { warnings if warnings else None }
512
- """
514
+ info_log = (
515
+ f"New Job running.. ID: { answer ['job_id' ]} "
516
+ f"| Status: { answer ['status' ]} ."
517
+ f" Got { len (warnings )} warnings:"
518
+ f" { warnings if warnings else None } "
519
+ )
513
520
self .logger .info (info_log )
514
521
response .raise_for_status ()
515
522
except Exception as e :
@@ -813,12 +820,12 @@ def _new_analysis_playbook_cli(
813
820
814
821
# 2nd step: poll for result
815
822
if should_poll :
816
- if resp [ "status" ] != "accepted" :
823
+ if resp . get ( "status" , "" ) != "accepted" :
817
824
self .logger .fatal ("Can't poll a failed job" )
818
825
# import poll function
819
826
from .cli ._jobs_utils import _poll_for_job_cli
820
827
821
- job_id = resp [ "job_id" ]
828
+ job_id = resp . get ( "job_id" , 0 )
822
829
_ = _poll_for_job_cli (self , job_id )
823
830
self .logger .info (
824
831
f"""
0 commit comments