Skip to content

Instantly share code, notes, and snippets.

@tmuth
Last active May 20, 2021 13:22
Show Gist options
  • Save tmuth/18666e670ca3489c3a576e1a6f3391c6 to your computer and use it in GitHub Desktop.
Save tmuth/18666e670ca3489c3a576e1a6f3391c6 to your computer and use it in GitHub Desktop.
Simple get search to pandas data frame
import urllib
import requests
import aiohttp
from pprint import pprint
# disable SSL warnings
import urllib3
urllib3.disable_warnings()
#df = dd.read_csv(filename)
baseurl = 'https://localhost:8089'
# can use "tokens" here
userName = 'admin'
password = 'welcome1'
url = baseurl + '/servicesNS/admin/search/search/jobs/export'
searchQuery = 'search index=people-test | table state,email | sort -1 | head 1000'
body=urllib.parse.urlencode({'search': searchQuery,'output_mode':'csv','earliest_time': "2021-01-01T12:00:00.000-07:00"})
#r = requests.post(url, auth=(userName, password),verify = False,data=body)
#payload = {'search': 'value1', 'key2': 'value2'}
#params=payload
r2 = requests.get(url, auth=(userName, password),verify = False,params=body)
pprint(str(r2.content))
import pandas as pd
from io import StringIO
import io, pkgutil
import csv
#df = pd.read_csv(io.BytesIO((r2.content)),delimiter="\n",skipinitialspace=False,sep=',',header=1,quoting=csv.QUOTE_ALL,encoding="utf-8",quotechar='"',escapechar="/").replace('"','', regex=True)
df = pd.read_csv(io.BytesIO((r2.content)),header=0,encoding="utf-8").replace('"','', regex=True)
df.head(20)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment