From fbe5414e9c3c449d0b154b3b6bd1e9ab7fb4f0f9 Mon Sep 17 00:00:00 2001 From: Anatoli Babenia Date: Wed, 29 Jul 2020 14:55:08 +0300 Subject: [PATCH] Write log as binary file in Python 3 Fixes File "bin/srv.py", line 101, in log_query my_file.write(log_entry.encode('utf-8')+"\n") TypeError: can't concat str to bytes --- bin/srv.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bin/srv.py b/bin/srv.py index 77c3286..52aaff1 100644 --- a/bin/srv.py +++ b/bin/srv.py @@ -96,9 +96,9 @@ def log_query(ip_addr, found, topic, user_agent): """ Log processed query and some internal data """ - log_entry = "%s %s %s %s" % (ip_addr, found, topic, user_agent) - with open(CONFIG["path.log.queries"], 'a') as my_file: - my_file.write(log_entry.encode('utf-8')+"\n") + log_entry = "%s %s %s %s\n" % (ip_addr, found, topic, user_agent) + with open(CONFIG["path.log.queries"], 'ab') as my_file: + my_file.write(log_entry.encode('utf-8')) def get_request_ip(req): """