【问题标题】:How to execute the following command using Python?如何使用 Python 执行以下命令?
【发布时间】:2019-09-18 00:18:28
【问题描述】:

如果有人帮助我了解如何使用 python 执行以下命令,那将是一个很大的帮助:

curl -X POST https://insights-collector.newrelic.com/v1/accounts/YOUR_ACCOUNT_ID/events -H "Content-Type: application/json" -H "X-Insert-Key: YOUR_KEY_HERE" -d '{"eventType":"自定义事件名称", "attribute1": “价值”}'

SQL查询结果需要转成JSON格式,使用上述命令推送到新的relic。

【问题讨论】:

  • 好像已经回答了,请参考stackoverflow.com/questions/26000336/…
  • 你尝试过做什么?
  • @yanivoliver : 你好.. 我已经获取了一个 mysql 查询结果并转换为 json 格式。我必须使用上面提到的命令将 json 数据推送到新的遗物。因为,我是 python 新手,所以我不清楚如何使用 python 执行上述命令。谢谢!
  • @Dhamodharan:非常感谢。我想我错过了。

标签: python json python-3.x curl newrelic-platform


【解决方案1】:

尝试这样做

import requests

headers = {
    'Content-Type': 'application/json',
    'X-Insert-Key': 'YOUR_KEY_HERE',
}

data = '{"eventType":"Custom Event Name", "attribute1": "value"}'

response = requests.post('https://insights-collector.newrelic.com/v1/accounts/YOUR_ACCOUNT_ID/events', headers=headers, data=data)

【讨论】:

    猜你喜欢
    • 2018-06-25
    • 2014-10-18
    • 2016-01-05
    • 1970-01-01
    • 2019-05-04
    • 2020-09-18
    • 2020-05-05
    • 2017-07-30
    • 1970-01-01
    相关资源
    最近更新 更多