Skip to content

Commit 24f738b

Browse files
author
Mike Kistler
committed
Update user agent string to include OS and Python version info
1 parent f4d3e36 commit 24f738b

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

watson_developer_cloud/watson_developer_cloud_service.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414
import json as json_import
15+
import platform
1516
import os
1617
import requests
1718
import sys
@@ -103,6 +104,12 @@ def __init__(self, vcap_services_name, url, username=None, password=None,
103104
self.password = None
104105
self.default_headers = None
105106

107+
user_agent_string = 'watson-apis-python-sdk-' + __version__ # SDK version
108+
user_agent_string += ' ' + platform.system() # OS
109+
user_agent_string += ' ' + platform.release() # OS version
110+
user_agent_string += ' ' + platform.python_version() # Python version
111+
self.user_agent_header = {'user-agent': user_agent_string}
112+
106113
if x_watson_learning_opt_out:
107114
self.default_headers = {'x-watson-learning-opt-out': 'true'}
108115

@@ -273,8 +280,7 @@ def request(self, method, url, accept_json=False, headers=None,
273280

274281
input_headers = _remove_null_values(headers) if headers else {}
275282

276-
headers = CaseInsensitiveDict(
277-
{'user-agent': 'watson-developer-cloud-python-' + __version__})
283+
headers = CaseInsensitiveDict(self.user_agent_header)
278284
if self.default_headers is not None:
279285
headers.update(self.default_headers)
280286
if accept_json:

0 commit comments

Comments
 (0)