python - 使用 python 的 Splunk REST Api : 201 with curl, 404?

标签 python rest curl python-requests splunk

我正在尝试向 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}

我知道不安全警告来 self 的 verify=false。 header 似乎通过了(splunkResponse.erquest.headers 正确显示它们),而我的不同测试没有给出任何内容...

我错过了什么?

最佳答案

事实证明,当 python 是 GET 请求时,curl 是一个 POST 请求。已解决。

关于python - 使用 python 的 Splunk REST Api : 201 with curl, 404?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37271794/

相关文章:

python - 将 sys.stdout.write 与 pool.map 一起用于多处理 - 共享 sys.stdout

python - 警告未找到 :/favicon. ico

python - 根据与 A 点的距离在直线上找到 B 点

python - 表示连接切片的切片

rest - 如何以 RESTful 方式 "lazy load"?

java - 如何在 Java RS json 响应中为简单列表类型设置自定义名称

json - 如果模型具有 Int64,则放置/发布 json 不适用于 ODataController

php - 想要在一个请求中将数据从一个数据库插入到另一个数据库

php - Shopify - 添加新产品时出现 API 错误(词法 JSON 错误)

php - 在生产服务器上使用 PHP CURL 库发布数据时出错