-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Closed
Labels
Description
Like this, we will directly have the proxy and timeout parameters for the ClientSession, this will be very convenient in some situation.
class Client(aiohttp.ClientSession):
'''
based on aiohttp's ClientSession,and add:
- proxy proxy_auth (user,pass)
- timeout
'''
def __init__(self,timeout=None,proxy=None,proxy_auth=None,*args,**kwargs):
self.timeout = timeout
conn = None
if proxy:### handle proxy
if proxy_auth:
conn = aiohttp.ProxyConnector(proxy=proxy,proxy_auth=aiohttp.BasicAuth(proxy_auth[0], proxy_auth[1]))
else:
conn = aiohttp.ProxyConnector(proxy=proxy)
super().__init__(connector=conn,*args,**kwargs)
def _request(self,*args,**kwargs):
return asyncio.wait_for(super()._request(*args,**kwargs), self.timeout)
def _ws_connect(self,*args,**kwargs):
return asyncio.wait_for(super()._ws_connect(*args,**kwargs), self.timeout)
Reactions are currently unavailable