From 37cdd5dc4abafd435a30ec2f34e476955d1ef843 Mon Sep 17 00:00:00 2001 From: Henning Jacobs Date: Wed, 10 Feb 2016 13:06:44 +0100 Subject: [PATCH] #6 set proper User-Agent header --- tests/test_tokens.py | 1 + tokens/__init__.py | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/test_tokens.py b/tests/test_tokens.py index bb5cec1..4199f08 100644 --- a/tests/test_tokens.py +++ b/tests/test_tokens.py @@ -114,6 +114,7 @@ def test_refresh_invalid_response(monkeypatch, tmpdir): # verify that we use a proper HTTP timeout.. post.assert_called_with('https://example.org', data={'username': 'app', 'scope': 'myscope', 'password': 'pass', 'grant_type': 'password'}, + headers={'User-Agent': 'python-tokens/{}'.format(tokens.__version__)}, timeout=(1.25, 2.25), auth=('cid', 'sec')) response.json.return_value = {'access_token': '', 'expires_in': 100} diff --git a/tokens/__init__.py b/tokens/__init__.py index 2cefbdf..31830d5 100644 --- a/tokens/__init__.py +++ b/tokens/__init__.py @@ -113,7 +113,9 @@ def refresh(token_name): except KeyError as e: raise InvalidCredentialsError('Missing key: {}'.format(e)) - r = requests.post(url, data=body, auth=auth, timeout=request_timeout) + headers = {'User-Agent': 'python-tokens/{}'.format(__version__)} + + r = requests.post(url, data=body, auth=auth, timeout=request_timeout, headers=headers) r.raise_for_status() try: data = r.json()