예제 #1
0
def get_proxy_auth(proxy):
    if proxy.user:
        scheme = proxy.scheme
        if scheme == 'http':
            return BasicAuth(proxy.user, proxy.password)
        elif scheme == 'socks5':
            return Socks5Auth(proxy.user, proxy.password)
        elif scheme == 'socks4':
            return Socks4Auth(proxy.user)
        else:
            raise ValueError('Proxy protocol must be http, socks5, or socks4.')
예제 #2
0
def socks_connector(proxy, loop=None):
    loop = loop or get_event_loop()
    proxy = URL(proxy)
    auth = None
    if proxy.scheme == 'socks4':
        addr = Socks4Addr(proxy.host, proxy.port)
    else:
        addr = Socks5Addr(proxy.host, proxy.port)
        if proxy.user and proxy.password:
            auth = Socks5Auth(proxy.user, proxy.password)
    return SocksConnector(proxy=addr,
                          proxy_auth=auth,
                          limit=300,
                          loop=loop,
                          remote_resolve=False,
                          verify_ssl=False)
예제 #3
0
 def proxy(self, proxy):
     if proxy is None:
         self._proxy = proxy
     else:
         self._proxy = URL(proxy)
         if self._proxy.user:
             scheme = self._proxy.scheme
             if scheme == 'http':
                 self.proxy_auth = BasicAuth(self._proxy.user,
                                             self._proxy.password)
             elif scheme == 'socks5':
                 self.proxy_auth = Socks5Auth(self._proxy.user,
                                              self._proxy.password)
             elif scheme == 'socks4':
                 self.proxy_auth = Socks4Auth(self._proxy.user)
             else:
                 raise ValueError(
                     'Proxy protocol must be http, socks5, or socks4.')