Splunk REST Api:201 带卷曲,404 带 python?
Splunk REST Api : 201 with curl, 404 with python?
我正在尝试针对 Splunk REST Api 提出请求。使用 curl 调用 Api 时效果很好:
curl -k https://host:8090/services/collector/event -H "Authorization: Splunk AUTH_CODE" -d '{"event":"Hello, World!","source":"Airwatch","index":"client-myclient"}'
{"text":"Success","code":0}%
但是当我尝试在 python 中提取相同的请求时,出现 404 错误:
splunkhost = 'MY_IP'
splunkUrl = 'https://%s:8090/services/collector/event' % splunkhost
splunkData = {'index':'client-myclient','event':'Event Python Test'}
splunkResponse = requests.get(splunkUrl, headers={'Authorization': 'Splunk AUTH_CODE'}, data = splunkData, verify=False)
print splunkResponse.text
/Library/Python/2.7/site-packages/requests/packages/urllib3/connectionpool.py:789: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.org/en/latest/security.html InsecureRequestWarning)
{"text":"The requested URL was not found on this server.","code":404}
我知道不安全警告来自我的 verify=false。 headers 似乎通过了(splunkResponse.erquest.headers 正确显示了它们),而我的不同测试没有给出任何东西...
我错过了什么?
原来 curl 是一个 POST 请求,而 python 是一个 GET 请求。已解决。
我正在尝试针对 Splunk REST Api 提出请求。使用 curl 调用 Api 时效果很好:
curl -k https://host:8090/services/collector/event -H "Authorization: Splunk AUTH_CODE" -d '{"event":"Hello, World!","source":"Airwatch","index":"client-myclient"}'
{"text":"Success","code":0}%
但是当我尝试在 python 中提取相同的请求时,出现 404 错误:
splunkhost = 'MY_IP'
splunkUrl = 'https://%s:8090/services/collector/event' % splunkhost
splunkData = {'index':'client-myclient','event':'Event Python Test'}
splunkResponse = requests.get(splunkUrl, headers={'Authorization': 'Splunk AUTH_CODE'}, data = splunkData, verify=False)
print splunkResponse.text
/Library/Python/2.7/site-packages/requests/packages/urllib3/connectionpool.py:789: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.org/en/latest/security.html InsecureRequestWarning)
{"text":"The requested URL was not found on this server.","code":404}
我知道不安全警告来自我的 verify=false。 headers 似乎通过了(splunkResponse.erquest.headers 正确显示了它们),而我的不同测试没有给出任何东西...
我错过了什么?
原来 curl 是一个 POST 请求,而 python 是一个 GET 请求。已解决。