Skip to content

Commit fbe5414

Browse files
committed
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
1 parent aae40ae commit fbe5414

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

bin/srv.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,9 @@ def log_query(ip_addr, found, topic, user_agent):
9696
"""
9797
Log processed query and some internal data
9898
"""
99-
log_entry = "%s %s %s %s" % (ip_addr, found, topic, user_agent)
100-
with open(CONFIG["path.log.queries"], 'a') as my_file:
101-
my_file.write(log_entry.encode('utf-8')+"\n")
99+
log_entry = "%s %s %s %s\n" % (ip_addr, found, topic, user_agent)
100+
with open(CONFIG["path.log.queries"], 'ab') as my_file:
101+
my_file.write(log_entry.encode('utf-8'))
102102

103103
def get_request_ip(req):
104104
"""

0 commit comments

Comments
 (0)