【问题标题】:Cisco AMP API python script思科 AMP API python 脚本
【发布时间】: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:&lt;password&gt; 'api.amp.cisco.com/v1/events' -o "ciscoamp_eventsAPI.txt"

标签: python json python-requests cisco


【解决方案1】:

假设您的其余代码工作正常...

response = requests.post(url, data=payload, headers=headers)

print (json.dumps(response.text))

你也可以试试这个

print(response.json())

【讨论】:

  • 同样的错误,我不确定有效载荷部分的正确使用。我将工作 curl 脚本放在上面,但我不确定如何在 python 中执行此操作。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2022-10-07
  • 2021-06-05
  • 1970-01-01
  • 1970-01-01
  • 2022-06-24
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多