diff --git a/csv_to_elastic.py b/csv_to_elastic.py index 75a3924..16f3a7d 100644 --- a/csv_to_elastic.py +++ b/csv_to_elastic.py @@ -149,6 +149,8 @@ def send_to_elastic(elastic_address, endpoint, ssl, username, password, to_elast headers = {"Content-type": "application/json", "Accept": "text/plain"} + request_body = to_elastic_string.encode("utf-8") + if not username is None: auth = b64encode(bytes("{}:{}".format(username,password), "utf-8")).decode("ascii") if ssl or "localhost" in elastic_address: @@ -156,10 +158,10 @@ def send_to_elastic(elastic_address, endpoint, ssl, username, password, to_elast else: print("*** Warning: Refusing to remotely transmit user/pass unencrypted.") - connection.request('POST', url=endpoint, headers = headers, body=to_elastic_string) + connection.request('POST', url = endpoint, headers = headers, body = request_body) response = connection.getresponse() - body = response.read().decode('utf-8') - response_details=json.loads(body) + response_body = response.read().decode('utf-8') + response_details=json.loads(response_body) if response.status != 200: print ("\n*** Error occured before import. ***")