python - 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
是我用来查询所有其他信息的标题值的字典。
任何帮助,将不胜感激。
解决方案
由于您是通过上传文件files=_files
,所以您不应该指定Content-type
. Content-type
应该由请求库设置。阅读: 上传内容时 HTTP 请求中的 Content-Type 值是什么?. 尝试删除_head['Content-type'] = ''
并更改_files
为_files = {"file": open(_path, 'rb')}
推荐阅读
- python-import - Jython:itertools 在哪里?
- git - git clone 接收对象和结帐是否相同
- javascript - 如何在 Choices.js 中禁用按字母顺序对项目进行自动排序?
- python - python pandas将多年的yyyy-mm-dd分配给累积的周数
- php - 用于插入和更新数据的单一表单
- android - 为什么我的启动器图标看起来不同?
- android - 我想从本机活动传递数据以使用 android 中的桥接来反应本机 js 文件
- python - 当使用我不想修改的外部函数生成绘图时,如何使用 Jupyter Notebook 将图形保存在文件夹中?
- javascript - 引用相同数据修改后引用实体中的子网格
- openshift - OpenShift 补丁服务端口号