diff --git a/sanic/request.py b/sanic/request.py index 57b4773c..69307222 100644 --- a/sanic/request.py +++ b/sanic/request.py @@ -143,7 +143,8 @@ class Request(dict): @property def ip(self): if not hasattr(self, '_ip'): - self._ip = self.transport.get_extra_info('peername') + self._ip = (self.transport.get_extra_info('peername') or + (None, None)) return self._ip @property 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) })