我尝试使用python和Nessus REST API (func POST / file / upload )将一个导出的扫描(.nessus)文件上传到Nessus Community Edition服务器,但是我在响应中不断得到类似以下{"fileuploaded":null}的响应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我在headers dict中取消设置Content-type键的原因是我得到了一个{'error': Content-type: application/json not supported'}
_path包含文件路径。
_head是我用来查询所有其他信息的标头值的字典。
任何帮助都将不胜感激。
发布于 2018-12-12 14:28:18
由于您是通过files=_files上传文件,因此不应指定Content-type。Content-type应该由请求库设置。阅读:Whats Content-Type value within a HTTP-Request when uploading content?。尝试删除_head['Content-type'] = ''并将_files更改为_files = {"file": open(_path, 'rb')}
https://stackoverflow.com/questions/53723093
复制相似问题