这是我的原始代码
import urllib, urllib2
from xml.dom import minidom
base_url = 'test.com:8000'
username = 'MyId'
password = 'passwd'
search_query = 'search error | head 10'
# Login and get the session key
request = urllib2.Request(base_url + '/servicesNS/MyId/search/auth/login',
data = urllib.urlencode({'username': username, 'password': password}))
server_content = urllib2.urlopen(request)
session_key = minidom.parseString(server_content.read()).\
getElementsByTagName('sessionKey')[0].childNodes[0].nodeValue
print "Session Key: %s" % session_key
# Perform a search
request = urllib2.Request(base_url + '/servicesNS/MyId/search/search/jobs/export',
data = urllib.urlencode({'search': search_query,'output_mode': 'json'}),
headers = { 'Authorization': ('Splunk %s' %session_key)})
search_results = urllib2.urlopen(request)
print search_results.read()
它导致404错误,所以我决定使用Curl。
我有这个卷曲推荐
curl -k -u myID:Passwd -d 'search="google.com | head 10"' -d "output_mode=json" https://test.com:8089/servicesNS/myId/search/search/jobs/export
我正在尝试使用pycurl来调用Joson。
如何将其转换为pycurl?
提前谢谢。