这是我的原始代码
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?
先感谢您.
将curl命令行转换为使用libcurl的任何东西(如pycurl或其他绑定)的最佳方法是运行命令行并在其后附加" --libcurl output.c",然后检查创建的胚胎为然后它显示了curl必须做什么.
将该C代码转换为pycurl代码通常是微不足道的.