首页 > 解决方案 > Nessus 文件上传 REST API

问题描述

我正在尝试使用 python 和 Nessus REST API (func POST /file/upload) 将导出的扫描 (.nessus) 文件上传到 Nessus 社区版服务器,但是我在响应中不断收到null这样{"fileuploaded":null}的响应。

我似乎无法在 API 文档中看到还需要什么。

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

我在标题字典中取消设置键的原因Content-type是我得到了一个{'error': Content-type: application/json not supported'}

_path包含文件路径。

_head是我用来查询所有其他信息的标题值的字典。

任何帮助,将不胜感激。

标签: pythonrestpython-requestsnessus

解决方案


由于您是通过上传文件files=_files,所以您不应该指定Content-type. Content-type应该由请求库设置。阅读: 上传内容时 HTTP 请求中的 Content-Type 值是什么?. 尝试删除_head['Content-type'] = ''并更改_files_files = {"file": open(_path, 'rb')}


推荐阅读