@@ -51,6 +51,8 @@ def __init__(
5151 use_sync_aiohttp : bool = False ,
5252 session : Optional [aiohttp .ClientSession ] = None ,
5353 headers : Optional [dict ] = None ,
54+ user_agent_prefix : Optional [str ] = None ,
55+ user_agent_suffix : Optional [str ] = None ,
5456 ):
5557 self .token = None if token is None else token .strip ()
5658 self .base_url = base_url
@@ -61,6 +63,9 @@ def __init__(
6163 self .use_sync_aiohttp = use_sync_aiohttp
6264 self .session = session
6365 self .headers = headers or {}
66+ self .headers ["User-Agent" ] = get_user_agent (
67+ user_agent_prefix , user_agent_suffix
68+ )
6469 self ._logger = logging .getLogger (__name__ )
6570 self ._event_loop = loop
6671
@@ -110,6 +115,9 @@ def api_call( # skipcq: PYL-R1710
110115 """
111116
112117 api_url = _get_url (self .base_url , api_method )
118+ headers = headers or {}
119+ headers .update (self .headers )
120+
113121 req_args = _build_req_args (
114122 token = self .token ,
115123 http_verb = http_verb ,
@@ -483,10 +491,7 @@ def _perform_urllib_http_request(
483491 def _build_urllib_request_headers (
484492 self , token : str , has_json : bool , has_files : bool , additional_headers : dict
485493 ) -> Dict [str , str ]:
486- headers = {
487- "User-Agent" : get_user_agent (),
488- "Content-Type" : "application/x-www-form-urlencoded" ,
489- }
494+ headers = {"Content-Type" : "application/x-www-form-urlencoded" }
490495 headers .update (self .headers )
491496 if token :
492497 headers .update ({"Authorization" : "Bearer {}" .format (token )})
0 commit comments