Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Send python version in user-agent string #125

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 13, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,13 @@ def setUp(self):
def test_request(self, mock):
self.client.request("2010-04-01", method="GET")
mock.assert_called_with("GET", "https://api.twilio.com/2010-04-01",
headers={"User-Agent": 'twilio-python',
headers={"User-Agent": ANY,
'Accept-Charset': 'utf-8'},
params={}, auth=AUTH, data=None)
called_kwargs = mock.mock_calls[0][2]
self.assertTrue(
'twilio-python' in called_kwargs['headers']['User-Agent']
)

def test_connect_apps(self):
self.assertIsInstance(self.client.connect_apps,
Expand Down
9 changes: 8 additions & 1 deletion twilio/rest/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import logging
import os
import platform
from twilio import TwilioException
from twilio import __version__ as LIBRARY_VERSION
from twilio.rest.resources import make_request
from twilio.rest.resources import Accounts
from twilio.rest.resources import Applications
Expand Down Expand Up @@ -76,8 +78,13 @@ def request(self, path, method=None, vars=None):
elif method == "POST" or method == "PUT":
data = vars

user_agent = "twilio-python %s (python-%s)" % (
LIBRARY_VERSION,
platform.python_version(),
)

headers = {
"User-Agent": "twilio-python",
"User-Agent": user_agent,
"Accept-Charset": "utf-8",
}

Expand Down