我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用socks.PROXY_TYPE_SOCKS4。
def _get_proxy(self): url_dissected = url_dissector.findall( self.session['proxy'] ) if url_dissected and len(url_dissected[0]) == 3: protocol, host, port = url_dissected[0] if protocol == 'socks5': return (socks.PROXY_TYPE_SOCKS5, host, int(port)) if protocol == 'socks4': return (socks.PROXY_TYPE_SOCKS4, host, int(port)) if protocol.startswith('http'): return (socks.PROXY_TYPE_HTTP, host, int(port)) return None, None, None
def get_proxy(): proxy_server = None proxy_type_id = 0 proxy_port = 8080 proxy_user = None proxy_pass = None try: proxy_server = __settings__.getSetting('proxy_server') proxy_type_id = __settings__.getSetting('proxy_type') proxy_port = int(__settings__.getSetting('proxy_port')) proxy_user = __settings__.getSetting('proxy_user') proxy_pass = __settings__.getSetting('proxy_pass') except: pass if proxy_type_id == '0': proxy_type = socks.PROXY_TYPE_HTTP_NO_TUNNEL elif proxy_type_id == '1': proxy_type = socks.PROXY_TYPE_HTTP elif proxy_type_id == '2': proxy_type = socks.PROXY_TYPE_SOCKS4 elif proxy_type_id == '3': proxy_type = socks.PROXY_TYPE_SOCKS5 proxy_dns = True return (proxy_type, proxy_server, proxy_port, proxy_dns, proxy_user, proxy_pass)
def __init__(self, proxy_url, username=None, password=None, num_pools=10, headers=None, **connection_pool_kw): parsed = parse_url(proxy_url) if parsed.scheme == 'socks5': socks_version = socks.PROXY_TYPE_SOCKS5 elif parsed.scheme == 'socks4': socks_version = socks.PROXY_TYPE_SOCKS4 else: raise ValueError( "Unable to determine SOCKS version from %s" % proxy_url ) self.proxy_url = proxy_url socks_options = { 'socks_version': socks_version, 'proxy_host': parsed.host, 'proxy_port': parsed.port, 'username': username, 'password': password, } connection_pool_kw['_socks_options'] = socks_options super(SOCKSProxyManager, self).__init__( num_pools, headers, **connection_pool_kw ) self.pool_classes_by_scheme = SOCKSProxyManager.pool_classes_by_scheme
def __init__(self, proxy_url, username=None, password=None, num_pools=10, headers=None, **connection_pool_kw): parsed = parse_url(proxy_url) if parsed.scheme == 'socks5': socks_version = socks.PROXY_TYPE_SOCKS5 rdns = False elif parsed.scheme == 'socks5h': socks_version = socks.PROXY_TYPE_SOCKS5 rdns = True elif parsed.scheme == 'socks4': socks_version = socks.PROXY_TYPE_SOCKS4 rdns = False elif parsed.scheme == 'socks4a': socks_version = socks.PROXY_TYPE_SOCKS4 rdns = True else: raise ValueError( "Unable to determine SOCKS version from %s" % proxy_url ) self.proxy_url = proxy_url socks_options = { 'socks_version': socks_version, 'proxy_host': parsed.host, 'proxy_port': parsed.port, 'username': username, 'password': password, 'rdns': rdns } connection_pool_kw['_socks_options'] = socks_options super(SOCKSProxyManager, self).__init__( num_pools, headers, **connection_pool_kw ) self.pool_classes_by_scheme = SOCKSProxyManager.pool_classes_by_scheme