From 4c7675939aa2b4cb3c3fcc08f9e62a7c8a6d4366 Mon Sep 17 00:00:00 2001 From: Johnny Date: Sat, 13 May 2017 17:35:04 +0200 Subject: [PATCH] Fix "TypeError: not all arguments converted during string formatting" socket.getpeername() returns AF_INET6 address family four-tuple, with flowid and scopeid. In server's write_response, an exception is raised when an IPv6 client connects due to four-tuple elements having two unused elements (flowid and scopeid). This makes sure that only the first two (host and port) are used in log string formatting. --- sanic/server.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sanic/server.py b/sanic/server.py index 96b8e91c..02db6fe5 100644 --- a/sanic/server.py +++ b/sanic/server.py @@ -201,7 +201,7 @@ class HttpProtocol(asyncio.Protocol): netlog.info('', extra={ 'status': response.status, 'byte': len(response.body), - 'host': '%s:%d' % self.request.ip, + 'host': '%s:%d' % (self.request.ip[0], self.request.ip[1]), 'request': '%s %s' % (self.request.method, self.request.url) })