0

I'm trying to upload an exported scan (.nessus) file to a Nessus Community Edition server using python and the Nessus REST API (func POST /file/upload) however I keep getting the response null like this {"fileuploaded":null} in the response.

I can't seem to see in the API doc's what else could be required.

def upload_scan_file(_path):
    _url = url+"/file/upload"
    _head['Content-type'] = ''
    _files = {"file": open(_path, 'rb'), "no_enc" : "0"}
    r = requests.post(_url, headers=_head, verify=False, files=_files)
    return r.text

The reason I unset the Content-type key in the headers dict is that I get a {'error': Content-type: application/json not supported'}

_path contains the file path.

_head is a dict of header values that I use to query all the others information.

Any help would be appreciated.

Dusty Boshoff
  • 1,016
  • 14
  • 39

1 Answers1

0

Since you are uploading file through files=_files , so you should not specify Content-type. Content-type ought to be set by requests library. Read: Whats Content-Type value within a HTTP-Request when uploading content?. Try to remove _head['Content-type'] = '' and change _files to _files = {"file": open(_path, 'rb')}

KC.
  • 2,981
  • 2
  • 12
  • 22
  • Thanks for your reply. I made the `_files` change and stripped the header. When using `files=_files` in the request I get `ConnectionError: ('Connection aborted.', BadStatusLine("''",))` but when I use the `data=_files` request then I get a `null` with HTTP 200 again – Dusty Boshoff Dec 12 '18 at 08:30
  • When i saw https://docs.tenable.com/sccv/api/File.html. I think whether i lack of `Content-Type` which inside dataBoundary (`{"file": ("this is file", open(_path, 'rb'), "text/plain" )}`). And we need to add `Origin`? – KC. Dec 12 '18 at 09:22