Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature required] does we can add the timeout or proxy parameters directly #711

Closed
a358003542 opened this issue Dec 28, 2015 · 3 comments
Closed
Labels

Comments

@a358003542
Copy link

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)
@asvetlov
Copy link
Member

Sorry, I've declined your feature request.

  1. Connector has much more options than just proxy_auth. Moreover, params for TCPConnector and UnixConnector are ambiguous. Putting all together makes a mess. Recommended way to create session with proxy is ClientSession(connector=ProxyConnector(proxy, proxy_auth=BasicAuth(login, password)).
    You still may use your own Client class provided above in your code.
  2. Proposed timeout parameter works only for connection establishment and sending request headers.
    It doesn't include time for sending request body and retrieving response back.
    Most likely users need both.
    The recommended way is using Timeout class:
    with aiohttp.Timeout(0.001):
        async with aiohttp.get('https://github.com') as r:
            await r.text()

@a358003542
Copy link
Author

OK, listening and learned.

@lock
Copy link

lock bot commented Oct 29, 2019

This thread has been automatically locked since there has not been
any recent activity after it was closed. Please open a new issue for
related bugs.

If you feel like there's important points made in this discussion,
please include those exceprts into that new issue.

@lock lock bot added the outdated label Oct 29, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 29, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants