Created
July 11, 2020 19:51
-
-
Save archcloudlabs/f9467398b02bbef17c83c77dccd00646 to your computer and use it in GitHub Desktop.
Python + Elasticsearch (TLS configured + Auth)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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