Skip to content

Instantly share code, notes, and snippets.

@archcloudlabs
Created July 11, 2020 19:51
Show Gist options
  • Save archcloudlabs/f9467398b02bbef17c83c77dccd00646 to your computer and use it in GitHub Desktop.
Save archcloudlabs/f9467398b02bbef17c83c77dccd00646 to your computer and use it in GitHub Desktop.
Python + Elasticsearch (TLS configured + Auth)
#!/usr/bin/python3
"""
Example Template for ES w/ AUTH
https://stackoverflow.com/questions/50366668/authentication-in-elasticsearch-using-python
"""
try:
import sys
import requests
from datetime import datetime
except ImportError as ie:
print("[!] Import error, I do not have %s" % ie)
sys.exit(1)
rhost = "https://127.0.0.1"
rport = "9200"
index = "test"
creds = ('username', 'password')
postdata = {"test":"value"}
tls_verify=True
header = {"Content-Type": "application/json"}
req = requests.post(rhost+rport+index+"/_doc",
headers=header,
auth=creds,
verify=tls_verify)
print("[+] Status: %s" % str(req.status))
print("[+] Data : %s" % str(req.text))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment