2121import json
2222import logging
2323from email .utils import parsedate_tz , mktime_tz
24+ from platform import python_version , version as platform_version
2425from random import randint
2526from time import time , sleep , gmtime , strftime
2627
2930
3031from .auth import JWT , Auth , AccessRequest
3132from .error import UnavailableError , ClientError , RequestError , ServerError
33+ from .version import __version__ as umapi_version
3234
3335
3436class Connection :
@@ -52,6 +54,7 @@ def __init__(self,
5254 timeout_seconds = 60.0 ,
5355 throttle_actions = 10 ,
5456 throttle_commands = 10 ,
57+ user_agent = None ,
5558 ** kwargs ):
5659 """
5760 Open a connection for the given parameters that has the given options.
@@ -82,6 +85,7 @@ def __init__(self,
8285 :param timeout_seconds: How many seconds to wait for server response (default=60, <= 0 or None means forever)
8386 :param throttle_actions: Max number of actions to pack into a single call
8487 :param throttle_commands: Max number of commands allowed in a single action
88+ :param user_agent: (optional) string to use as User-Agent header (umapi-client/version data will be added)
8589
8690 Additional keywords are allowed to make it easy to pass a big dictionary with other values
8791 :param kwargs: any keywords passed that we ignore.
@@ -111,6 +115,10 @@ def __init__(self,
111115 else :
112116 raise ValueError ("Connector create: either auth (an Auth object) or auth_dict (a dictionary) is required" )
113117 self .session = requests .Session ()
118+ ua_string = "umapi-client/" + umapi_version + " Python/" + python_version () + " (" + platform_version () + ")"
119+ if user_agent and user_agent .strip ():
120+ ua_string = user_agent .strip () + " " + ua_string
121+ self .session .headers ["User-Agent" ] = ua_string
114122
115123 def _get_auth (self , ims_host , ims_endpoint_jwt ,
116124 tech_acct_id = None , api_key = None , client_secret = None , private_key_file = None ,
0 commit comments