Python urllib.getproxies() Examples

The following are 30 code examples of urllib.getproxies(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module urllib , or try the search function .
Example #1
Source File: util.py    From odoo12-x64 with GNU General Public License v3.0 6 votes vote down vote up
def get_soap_client(wsdlurl):  # pragma: no cover (not part of normal test suite)
    """Get a SOAP client for performing requests. The client is cached."""
    # this function isn't automatically tested because the functions using
    # it are not automatically tested
    if wsdlurl not in _soap_clients:
        # try zeep first
        try:
            from zeep import CachingClient
            client = CachingClient(wsdlurl).service
        except ImportError:
            # fall back to non-caching zeep client
            try:
                from zeep import Client
                client = Client(wsdlurl).service
            except ImportError:
                # other implementations require passing the proxy config
                try:
                    from urllib import getproxies
                except ImportError:
                    from urllib.request import getproxies
                # fall back to suds
                try:
                    from suds.client import Client
                    client = Client(wsdlurl, proxy=getproxies()).service
                except ImportError:
                    # use pysimplesoap as last resort
                    from pysimplesoap.client import SoapClient
                    client = SoapClient(wsdl=wsdlurl, proxy=getproxies())
        _soap_clients[wsdlurl] = client
    return _soap_clients[wsdlurl] 
Example #2
Source File: Robinhood.py    From robinhood-to-csv with MIT License 6 votes vote down vote up
def __init__(self):
        self.session = requests.session()
        try:
            self.session.proxies = urllib.getproxies() #py2
        except:
            self.session.proxies = urllib.request.getproxies() #py3
        self.headers = {
            "Accept": "*/*",
            "Accept-Encoding": "gzip, deflate",
            "Accept-Language": "en;q=1, fr;q=0.9, de;q=0.8, ja;q=0.7, nl;q=0.6, it;q=0.5",
            "Content-Type": "application/x-www-form-urlencoded; charset=utf-8",
            "X-Robinhood-API-Version": "1.0.0",
            "Connection": "keep-alive",
            "User-Agent": "Robinhood/823 (iPhone; iOS 7.1.2; Scale/2.00)"
        }
        self.session.headers = self.headers 
Example #3
Source File: timeouturlopen.py    From p2ptv-pi with MIT License 6 votes vote down vote up
def find_proxy(url):
    scheme, netloc, path, pars, query, fragment = urlparse.urlparse(url)
    proxies = urllib.getproxies()
    proxyhost = None
    if scheme in proxies:
        if '@' in netloc:
            sidx = netloc.find('@') + 1
        else:
            sidx = 0
        eidx = netloc.find(':')
        if eidx == -1:
            eidx = len(netloc)
        host = netloc[sidx:eidx]
        if not (host == '127.0.0.1' or urllib.proxy_bypass(host)):
            proxyurl = proxies[scheme]
            proxyelems = urlparse.urlparse(proxyurl)
            proxyhost = proxyelems[1]
    if DEBUG:
        print >> sys.stderr, 'find_proxy: Got proxies', proxies, 'selected', proxyhost, 'URL was', url
    return proxyhost 
Example #4
Source File: Robinhood.py    From Robinhood with MIT License 6 votes vote down vote up
def __init__(self, username, password):
        self.session = requests.session()
        self.session.proxies = urllib.getproxies()
        self.username = username
        self.password = password
        self.headers = {
            "Accept": "*/*",
            "Accept-Encoding": "gzip, deflate",
            "Accept-Language": "en;q=1, fr;q=0.9, de;q=0.8, ja;q=0.7, nl;q=0.6, it;q=0.5",
            "Content-Type": "application/x-www-form-urlencoded; charset=utf-8",
            "X-Robinhood-API-Version": "1.0.0",
            "Connection": "keep-alive",
            "User-Agent": "Robinhood/823 (iPhone; iOS 7.1.2; Scale/2.00)"
        }
        
        self.session.headers = self.headers
        self.login()
        
        ## set account url
        acc = self.get_account_number()
        self.account_url = self.endpoints['accounts'] + acc + "/" 
Example #5
Source File: conarycfg.py    From conary with Apache License 2.0 6 votes vote down vote up
def getProxyMap(cfg):
    """
    Return the proxyMap, or create it from old-style proxy/conaryProxy
    entries.
    """
    if cfg.proxyMap:
        return cfg.proxyMap

    # This creates a new proxyMap instance. We don't want to override the
    # config's proxyMap, since old consumers of the API may modify the settings
    # in-place and expect the changes to take effect.
    proxyDict = urllib.getproxies()
    proxyDict.update(cfg.proxy)
    if hasattr(cfg, 'conaryProxy'):
        for scheme, url in cfg.conaryProxy.items():
            if url.startswith('http:'):
                url = 'conary:' + url[5:]
            elif url.startswith('https:'):
                url = 'conarys:' + url[6:]
            proxyDict[scheme] = url
    return proxy_map.ProxyMap.fromDict(proxyDict)


# These are regrettably part of the module's published API
# pyflakes=ignore 
Example #6
Source File: _urllib2_fork.py    From BruteXSS with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, proxies=None, proxy_bypass=None):
        if proxies is None:
            proxies = getproxies()

        assert hasattr(proxies, 'has_key'), "proxies must be a mapping"
        self.proxies = proxies
        for type, url in proxies.items():
            setattr(self, '%s_open' % type,
                    lambda r, proxy=url, type=type, meth=self.proxy_open: \
                    meth(r, proxy, type))
        if proxy_bypass is None:
            proxy_bypass = urllib.proxy_bypass
        self._proxy_bypass = proxy_bypass 
Example #7
Source File: urllib2.py    From CTFCrackTools with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, proxies=None):
        if proxies is None:
            proxies = getproxies()
        assert hasattr(proxies, 'has_key'), "proxies must be a mapping"
        self.proxies = proxies
        for type, url in proxies.items():
            setattr(self, '%s_open' % type,
                    lambda r, proxy=url, type=type, meth=self.proxy_open: \
                    meth(r, proxy, type)) 
Example #8
Source File: urllib2.py    From CTFCrackTools with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, proxies=None):
        if proxies is None:
            proxies = getproxies()
        assert hasattr(proxies, 'has_key'), "proxies must be a mapping"
        self.proxies = proxies
        for type, url in proxies.items():
            setattr(self, '%s_open' % type,
                    lambda r, proxy=url, type=type, meth=self.proxy_open: \
                    meth(r, proxy, type)) 
Example #9
Source File: urllib2.py    From canape with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, proxies=None):
        if proxies is None:
            proxies = getproxies()
        assert hasattr(proxies, 'has_key'), "proxies must be a mapping"
        self.proxies = proxies
        for type, url in proxies.items():
            setattr(self, '%s_open' % type,
                    lambda r, proxy=url, type=type, meth=self.proxy_open: \
                    meth(r, proxy, type)) 
Example #10
Source File: urllib2.py    From unity-python with MIT License 5 votes vote down vote up
def __init__(self, proxies=None):
        if proxies is None:
            proxies = getproxies()
        assert hasattr(proxies, 'has_key'), "proxies must be a mapping"
        self.proxies = proxies
        for type, url in proxies.items():
            setattr(self, '%s_open' % type,
                    lambda r, proxy=url, type=type, meth=self.proxy_open: \
                    meth(r, proxy, type)) 
Example #11
Source File: urllib2.py    From PokemonGo-DesktopMap with MIT License 5 votes vote down vote up
def __init__(self, proxies=None):
        if proxies is None:
            proxies = getproxies()
        assert hasattr(proxies, 'has_key'), "proxies must be a mapping"
        self.proxies = proxies
        for type, url in proxies.items():
            setattr(self, '%s_open' % type,
                    lambda r, proxy=url, type=type, meth=self.proxy_open: \
                    meth(r, proxy, type)) 
Example #12
Source File: urllib2.py    From RevitBatchProcessor with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, proxies=None):
        if proxies is None:
            proxies = getproxies()
        assert hasattr(proxies, 'has_key'), "proxies must be a mapping"
        self.proxies = proxies
        for type, url in proxies.items():
            setattr(self, '%s_open' % type,
                    lambda r, proxy=url, type=type, meth=self.proxy_open: \
                    meth(r, proxy, type)) 
Example #13
Source File: urllib2.py    From CTFCrackTools-V2 with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, proxies=None):
        if proxies is None:
            proxies = getproxies()
        assert hasattr(proxies, 'has_key'), "proxies must be a mapping"
        self.proxies = proxies
        for type, url in proxies.items():
            setattr(self, '%s_open' % type,
                    lambda r, proxy=url, type=type, meth=self.proxy_open: \
                    meth(r, proxy, type)) 
Example #14
Source File: urllib2.py    From CTFCrackTools-V2 with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, proxies=None):
        if proxies is None:
            proxies = getproxies()
        assert hasattr(proxies, 'has_key'), "proxies must be a mapping"
        self.proxies = proxies
        for type, url in proxies.items():
            setattr(self, '%s_open' % type,
                    lambda r, proxy=url, type=type, meth=self.proxy_open: \
                    meth(r, proxy, type)) 
Example #15
Source File: _urllib2_fork.py    From pelisalacarta-ce with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, proxies=None, proxy_bypass=None):
        if proxies is None:
            proxies = getproxies()

        assert hasattr(proxies, 'has_key'), "proxies must be a mapping"
        self.proxies = proxies
        for type, url in proxies.items():
            setattr(self, '%s_open' % type,
                    lambda r, proxy=url, type=type, meth=self.proxy_open: \
                    meth(r, proxy, type))
        if proxy_bypass is None:
            proxy_bypass = urllib.proxy_bypass
        self._proxy_bypass = proxy_bypass 
Example #16
Source File: proxy_map.py    From conary with Apache License 2.0 5 votes vote down vote up
def fromEnvironment(cls):
        return cls.fromDict(urllib.getproxies()) 
Example #17
Source File: util.py    From odoo13-x64 with GNU General Public License v3.0 5 votes vote down vote up
def get_soap_client(wsdlurl, timeout=30):  # pragma: no cover (not part of normal test suite)
    """Get a SOAP client for performing requests. The client is cached. The
    timeout is in seconds."""
    # this function isn't automatically tested because the functions using
    # it are not automatically tested
    if (wsdlurl, timeout) not in _soap_clients:
        # try zeep first
        try:
            from zeep.transports import Transport
            transport = Transport(timeout=timeout)
            from zeep import CachingClient
            client = CachingClient(wsdlurl, transport=transport).service
        except ImportError:
            # fall back to non-caching zeep client
            try:
                from zeep import Client
                client = Client(wsdlurl, transport=transport).service
            except ImportError:
                # other implementations require passing the proxy config
                try:
                    from urllib import getproxies
                except ImportError:
                    from urllib.request import getproxies
                # fall back to suds
                try:
                    from suds.client import Client
                    client = Client(
                        wsdlurl, proxy=getproxies(), timeout=timeout).service
                except ImportError:
                    # use pysimplesoap as last resort
                    try:
                        from pysimplesoap.client import SoapClient
                        client = SoapClient(
                            wsdl=wsdlurl, proxy=getproxies(), timeout=timeout)
                    except ImportError:
                        raise ImportError(
                            'No SOAP library (such as zeep) found')
        _soap_clients[(wsdlurl, timeout)] = client
    return _soap_clients[(wsdlurl, timeout)] 
Example #18
Source File: urllib2.py    From jawfish with MIT License 5 votes vote down vote up
def __init__(self, proxies=None):
        if proxies is None:
            proxies = getproxies()
        assert hasattr(proxies, 'has_key'), "proxies must be a mapping"
        self.proxies = proxies
        for type, url in proxies.items():
            setattr(self, '%s_open' % type,
                    lambda r, proxy=url, type=type, meth=self.proxy_open: \
                    meth(r, proxy, type)) 
Example #19
Source File: urllib2.py    From medicare-demo with Apache License 2.0 5 votes vote down vote up
def __init__(self, proxies=None):
        if proxies is None:
            proxies = getproxies()
        assert hasattr(proxies, 'has_key'), "proxies must be a mapping"
        self.proxies = proxies
        for type, url in proxies.items():
            setattr(self, '%s_open' % type,
                    lambda r, proxy=url, type=type, meth=self.proxy_open: \
                    meth(r, proxy, type)) 
Example #20
Source File: urllib2.py    From Splunking-Crime with GNU Affero General Public License v3.0 5 votes vote down vote up
def __init__(self, proxies=None):
        if proxies is None:
            proxies = getproxies()
        assert hasattr(proxies, 'has_key'), "proxies must be a mapping"
        self.proxies = proxies
        for type, url in proxies.items():
            setattr(self, '%s_open' % type,
                    lambda r, proxy=url, type=type, meth=self.proxy_open: \
                    meth(r, proxy, type)) 
Example #21
Source File: urllib2.py    From datafari with Apache License 2.0 5 votes vote down vote up
def __init__(self, proxies=None):
        if proxies is None:
            proxies = getproxies()
        assert hasattr(proxies, 'has_key'), "proxies must be a mapping"
        self.proxies = proxies
        for type, url in proxies.items():
            setattr(self, '%s_open' % type,
                    lambda r, proxy=url, type=type, meth=self.proxy_open: \
                    meth(r, proxy, type)) 
Example #22
Source File: ravello_sdk.py    From python-sdk with Apache License 2.0 5 votes vote down vote up
def __init__(self, username=None, password=None, url=None, timeout=None, retries=None, proxy_url=None, eph_token=None, identity_domain=None):
        """Create a new client.

        The *username* and *password* parameters specify the credentials to use
        when connecting to the API. When the organization of the user has an identity domain,
        the user must specify it or include it in the username: <identity_domain>/<username>.
        When the organization doesnt have an identity domain use only the username.
        The *timeout* and *retries* parameters
        specify the default network system call time timeout and maximum number
        of retries respectively.
        *proxy_url* should be used when an HTTP proxy is in place.
        *eph_token* is ephemeral access token to be used instead of username/password.
        """
        self._identity_domain = identity_domain
        self._username = username
        self._password = password
        self.timeout = timeout if timeout is not None else self.default_timeout
        self.retries = retries if retries is not None else self.default_retries
        self.redirects = self.default_redirects
        self._logger = logging.getLogger('ravello')
        self._autologin = True
        self._connection = None
        self._user_info = None
        self._set_url(url or self.default_url)
        # Get proxy setting from environment variables
        try:
          self._proxies = urllib.getproxies()
        except:
          self._proxies = urllib.request.getproxies()
        if proxy_url is not None:
            self._proxies = {"http": proxy_url, "https": proxy_url}
        self._eph_token = eph_token 
Example #23
Source File: api.py    From clf with MIT License 5 votes vote down vote up
def _get_proxies(self):
        proxies = getproxies()

        proxy = {}
        if self.proxy:
            parsed_proxy = urlparse(self.proxy)
            proxy[parsed_proxy.scheme] = parsed_proxy.geturl()

        proxies.update(proxy)
        return proxies 
Example #24
Source File: urllib2.py    From pmatic with GNU General Public License v2.0 5 votes vote down vote up
def __init__(self, proxies=None):
        if proxies is None:
            proxies = getproxies()
        assert hasattr(proxies, 'has_key'), "proxies must be a mapping"
        self.proxies = proxies
        for type, url in proxies.items():
            setattr(self, '%s_open' % type,
                    lambda r, proxy=url, type=type, meth=self.proxy_open: \
                    meth(r, proxy, type)) 
Example #25
Source File: urllib2.py    From oss-ftp with MIT License 5 votes vote down vote up
def __init__(self, proxies=None):
        if proxies is None:
            proxies = getproxies()
        assert hasattr(proxies, 'has_key'), "proxies must be a mapping"
        self.proxies = proxies
        for type, url in proxies.items():
            setattr(self, '%s_open' % type,
                    lambda r, proxy=url, type=type, meth=self.proxy_open: \
                    meth(r, proxy, type)) 
Example #26
Source File: urllib2.py    From Computable with MIT License 5 votes vote down vote up
def __init__(self, proxies=None):
        if proxies is None:
            proxies = getproxies()
        assert hasattr(proxies, 'has_key'), "proxies must be a mapping"
        self.proxies = proxies
        for type, url in proxies.items():
            setattr(self, '%s_open' % type,
                    lambda r, proxy=url, type=type, meth=self.proxy_open: \
                    meth(r, proxy, type)) 
Example #27
Source File: urllib2.py    From BinderFilter with MIT License 5 votes vote down vote up
def __init__(self, proxies=None):
        if proxies is None:
            proxies = getproxies()
        assert hasattr(proxies, 'has_key'), "proxies must be a mapping"
        self.proxies = proxies
        for type, url in proxies.items():
            setattr(self, '%s_open' % type,
                    lambda r, proxy=url, type=type, meth=self.proxy_open: \
                    meth(r, proxy, type)) 
Example #28
Source File: urllib2.py    From GDCTSCP with GNU Affero General Public License v3.0 5 votes vote down vote up
def __init__(self, proxies=None):
        if proxies is None:
            proxies = getproxies()
        assert hasattr(proxies, 'has_key'), "proxies must be a mapping"
        self.proxies = proxies
        for type, url in proxies.items():
            setattr(self, '%s_open' % type,
                    lambda r, proxy=url, type=type, meth=self.proxy_open: \
                    meth(r, proxy, type)) 
Example #29
Source File: urllib2.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def __init__(self, proxies=None):
        if proxies is None:
            proxies = getproxies()
        assert hasattr(proxies, 'has_key'), "proxies must be a mapping"
        self.proxies = proxies
        for type, url in proxies.items():
            setattr(self, '%s_open' % type,
                    lambda r, proxy=url, type=type, meth=self.proxy_open: \
                    meth(r, proxy, type)) 
Example #30
Source File: urllib2.py    From meddle with MIT License 5 votes vote down vote up
def __init__(self, proxies=None):
        if proxies is None:
            proxies = getproxies()
        assert hasattr(proxies, 'has_key'), "proxies must be a mapping"
        self.proxies = proxies
        for type, url in proxies.items():
            setattr(self, '%s_open' % type,
                    lambda r, proxy=url, type=type, meth=self.proxy_open: \
                    meth(r, proxy, type))