【发布时间】:2018-01-30 22:18:04
【问题描述】:
我正在尝试编写一个脚本,以使用 cisco api 和 Python 从我们的 Cisco AMP 环境中提取事件。下面是我开始的,但我得到一个文件未找到错误“FileNotFoundError:[Errno 2]没有这样的文件或目录:'request.json'”
import requests
import json
url = 'https://<your_client_id>:<your_api_key>@api.amp.sourcefire.com/v1/events'
payload = open("request.json")
headers = {'content-type': 'application/json', 'Accept-Charset': 'UTF-8'}
response = requests.post(url, data=payload, headers=headers)
print (json.dumps(response))
感谢您的帮助。
【问题讨论】:
-
等等,刚刚发现错误在
payload = open("request.json")。你为什么要打开request.json? -
你能把它放在你问题的代码块中吗?
-
curl 脚本看起来像:
curl -X GET -H 'accept: application/json' -H 'content-type: application/json' --compressed -H 'Accept-Encoding: gzip, deflate' -u b7014a3aa062a91cb67e:<password> 'api.amp.cisco.com/v1/events' -o "ciscoamp_eventsAPI.txt"
标签: python json python-requests cisco