21
21
import json
22
22
import logging
23
23
from email .utils import parsedate_tz , mktime_tz
24
+ from platform import python_version , version as platform_version
24
25
from random import randint
25
26
from time import time , sleep , gmtime , strftime
26
27
29
30
30
31
from .auth import JWT , Auth , AccessRequest
31
32
from .error import UnavailableError , ClientError , RequestError , ServerError
33
+ from .version import __version__ as umapi_version
32
34
33
35
34
36
class Connection :
@@ -52,6 +54,7 @@ def __init__(self,
52
54
timeout_seconds = 60.0 ,
53
55
throttle_actions = 10 ,
54
56
throttle_commands = 10 ,
57
+ user_agent = None ,
55
58
** kwargs ):
56
59
"""
57
60
Open a connection for the given parameters that has the given options.
@@ -82,6 +85,7 @@ def __init__(self,
82
85
:param timeout_seconds: How many seconds to wait for server response (default=60, <= 0 or None means forever)
83
86
:param throttle_actions: Max number of actions to pack into a single call
84
87
: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)
85
89
86
90
Additional keywords are allowed to make it easy to pass a big dictionary with other values
87
91
:param kwargs: any keywords passed that we ignore.
@@ -111,6 +115,10 @@ def __init__(self,
111
115
else :
112
116
raise ValueError ("Connector create: either auth (an Auth object) or auth_dict (a dictionary) is required" )
113
117
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
114
122
115
123
def _get_auth (self , ims_host , ims_endpoint_jwt ,
116
124
tech_acct_id = None , api_key = None , client_secret = None , private_key_file = None ,
0 commit comments