Update user agent string to include OS and Python version info
# See the License for the specific language governing permissions and
# limitations under the License.
import json as json_import
+import platform
import os
import requests
import sys
@@ -103,6 +104,12 @@ class WatsonDeveloperCloudService(object):
self.password = None
self.default_headers = None
+ user_agent_string = 'watson-apis-python-sdk-' + __version__ # SDK version
+ user_agent_string += ' ' + platform.system() # OS
+ user_agent_string += ' ' + platform.release() # OS version
+ user_agent_string += ' ' + platform.python_version() # Python version
+ self.user_agent_header = {'user-agent': user_agent_string}
+
if x_watson_learning_opt_out:
self.default_headers = {'x-watson-learning-opt-out': 'true'}
@@ -273,8 +280,7 @@ class WatsonDeveloperCloudService(object):
input_headers = _remove_null_values(headers) if headers else {}
- headers = CaseInsensitiveDict(
- {'user-agent': 'watson-developer-cloud-python-' + __version__})
+ headers = CaseInsensitiveDict(self.user_agent_header)
if self.default_headers is not None:
headers.update(self.default_headers)
if accept_json:
