From a51b9c06cec07858a6f07215648c3be8b447d893 Mon Sep 17 00:00:00 2001 From: Changaco Date: Fri, 25 Jan 2019 18:14:03 +0100 Subject: [PATCH] adapt the `Request.source` property to python 3 --- liberapay/main.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/liberapay/main.py b/liberapay/main.py index 7236640d04..cc811715a9 100644 --- a/liberapay/main.py +++ b/liberapay/main.py @@ -235,7 +235,8 @@ def _Querystring_derive(self, **kw): raise Warning('pando.http.request.Request.source already exists') def _source(self): def f(): - addr = ip_address(self.environ[b'REMOTE_ADDR'].decode('ascii')) + addr = self.environ.get('REMOTE_ADDR') or self.environ[b'REMOTE_ADDR'] + addr = ip_address(addr.decode('ascii') if type(addr) is bytes else addr) trusted_proxies = getattr(self.website, 'trusted_proxies', None) forwarded_for = self.headers.get(b'X-Forwarded-For') self.__dict__['bypasses_proxy'] = bool(trusted_proxies)