如何使用Python执行以下命令?

2024-06-16 11:51:29 发布

您现在位置:Python中文网/ 问答频道 /正文

如果有人能帮助我理解如何使用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":"Custom Event Name", "attribute1": "value"}'

SQL查询结果需要转换为JSON格式,并且需要使用上述命令推送到newrelic。你知道吗


Tags: https命令comidyouraccountcontentcurl
1条回答
网友
1楼 · 发布于 2024-06-16 11:51:29

试着这样做

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)

相关问题 更多 >