需要将数据发布到REST API。一个字段incident_type需要以下面的JSON格式传递(必须包含括号,不能只是大括号):"incident_type_ids": [{
"name": "Phishing - General"
}],
当我尝试在我的代码中强制执行此操作时,不正确。通常会有一些额外的引号转义(例如output "incident_type_ids": "[\\"{ name : Phishing - General }\\"]":),这是因为我在incident type变量中对JSON数据进行了双重编码以强制添加括号(在第6行中,此后被注释掉):#incident variables
name = 'Incident Name 2'
description = 'This is the description'
corpID = 'id'
incident_type = '{ name : Phishing - General }'
#incident_type = json.dumps([incident_type])
incident_owner = 'Security Operations Center'
payload = {
'name':name,
'discovered_date':'0',
'owner_id':incident_owner,
'description':description,
'exposure_individual_name':corpID,
'incident_type_ids':incident_type
}
body=json.dumps(payload)
create = s.post(url, data=body, headers=headers, verify=False)
因为我注释掉了这一行,所以无法得到incident_type需要的格式(括号)。
如何incident_type在最终的格式中获得正确格式的变量payload?
输入手动使用产品的交互式REST API工作:{
"name": "Incident Name 2",
"incident_type_ids": [{
"name": "Phishing - General"
}],
"description": "This is the description",
"discovered_date": "0",
"exposure_individual_name": "id",
"owner_id": "Security Operations Center"
}