diff --git a/sanic/request.py b/sanic/request.py index 660fe6cb..add4ca3f 100644 --- a/sanic/request.py +++ b/sanic/request.py @@ -86,7 +86,7 @@ class Request(dict): :return: token related to request """ auth_header = self.headers.get('Authorization') - if 'Token ' in auth_header: + if auth_header is not None and 'Token ' in auth_header: return auth_header.partition('Token ')[-1] else: return auth_header diff --git a/tests/test_requests.py b/tests/test_requests.py index f77fd90f..06e2b7ae 100644 --- a/tests/test_requests.py +++ b/tests/test_requests.py @@ -182,6 +182,14 @@ def test_token(): assert request.token == token + # no Authorization headers + headers = { + 'content-type': 'application/json' + } + + request, response = app.test_client.get('/', headers=headers) + + assert request.token is None # ------------------------------------------------------------ #