【问题标题】:Nessus File upload REST APINessus 文件上传 REST API
【发布时间】:2018-12-11 11:22:33
【问题描述】:

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

我似乎无法在 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 是我用来查询所有其他信息的标头值的字典。

任何帮助将不胜感激。

【问题讨论】:

    标签: python rest python-requests nessus


    【解决方案1】:

    由于您是通过files=_files 上传文件,所以您不应该指定Content-typeContent-type 应该由 requests 库设置。阅读:Whats Content-Type value within a HTTP-Request when uploading content?。尝试删除_head['Content-type'] = ''并将_files更改为_files = {"file": open(_path, 'rb')}

    【讨论】:

    • 感谢您的回复。我进行了_files 更改并剥离了标题。在请求中使用files=_files 时,我得到ConnectionError: ('Connection aborted.', BadStatusLine("''",)),但是当我使用data=_files 请求时,我再次得到带有HTTP 200 的null
    • 当我看到docs.tenable.com/sccv/api/File.html。我想我是否缺少Content-Type 里面的dataBoundary ({"file": ("this is file", open(_path, 'rb'), "text/plain" )})。我们需要添加Origin?
    猜你喜欢
    • 2014-12-31
    • 1970-01-01
    • 2020-05-30
    • 2018-04-04
    • 1970-01-01
    • 1970-01-01
    • 2013-04-01
    • 1970-01-01
    • 2023-03-10
    相关资源
    最近更新 更多