From ac56352deb380176f13b805fa8244b33ae6666d7 Mon Sep 17 00:00:00 2001 From: liseri Date: Tue, 15 May 2018 14:55:57 +0800 Subject: [PATCH] Update csv_to_elastic.py encode request body with utf-8 --- csv_to_elastic.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) 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. ***")