Skip to content

Commit

Permalink
#6 set proper User-Agent header
Browse files Browse the repository at this point in the history
  • Loading branch information
hjacobs committed Feb 10, 2016
1 parent fa16cfc commit 37cdd5d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
1 change: 1 addition & 0 deletions tests/test_tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
4 changes: 3 additions & 1 deletion tokens/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 37cdd5d

Please sign in to comment.