How to use the httplib2.socks function in httplib2

To help you get started, we’ve selected a few httplib2 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github PaloAltoNetworks / Splunk_TA_paloalto / bin / splunk_ta_paloalto / cloudconnectlib / splunktalib / rest.py View on Github external
"password": yy,
                 "proxy_url": zz,
                 "proxy_port": aa,
                 "proxy_username": bb,
                 "proxy_password": cc,
                 "proxy_type": http,http_no_tunnel,sock4,sock5,
                 "proxy_rdns": 0 or 1,
             }
    :return: Http2.Http object
    """

    proxy_type_to_code = {
        "http": socks.PROXY_TYPE_HTTP,
        "http_no_tunnel": socks.PROXY_TYPE_HTTP_NO_TUNNEL,
        "socks4": socks.PROXY_TYPE_SOCKS4,
        "socks5": socks.PROXY_TYPE_SOCKS5,
    }
    if config.get("proxy_type") in proxy_type_to_code:
        proxy_type = proxy_type_to_code[config["proxy_type"]]
    else:
        proxy_type = socks.PROXY_TYPE_HTTP

    rdns = scu.is_true(config.get("proxy_rdns"))

    proxy_info = None
    if config.get("proxy_url") and config.get("proxy_port"):
        if config.get("proxy_username") and config.get("proxy_password"):
            proxy_info = ProxyInfo(proxy_type=proxy_type,
                                   proxy_host=config["proxy_url"],
                                   proxy_port=int(config["proxy_port"]),
                                   proxy_user=config["proxy_username"],
                                   proxy_pass=config["proxy_password"],
github linkedin / iris-relay / src / iris_relay / gmail.py View on Github external
"""Get a Message with given ID.

        :param msg_id: ID of Message to delete.
        :param user_id: User's email address. The special value "me"
            can be used to indicate the authenticated user.
        :return: A Message.
        :rtype: dict
        """
        self.connect()
        ret = {}
        try:
            ret = self.client.users().messages().get(
                userId=user_id,
                id=msg_id
            ).execute()
        except (socks.HTTPError, errors.HttpError) as error:
            logger.error('An error occurred: %s', error)
        else:
            logger.info('Message snippet: %s', ret.get('snippet'))
        return ret
github goodrain / rainbond-console / www / apiclient / regionapi.py View on Github external
def make_proxy_http(self, region_service_info):
        proxy_info = region_service_info['proxy']
        if proxy_info['type'] == 'http':
            proxy_type = httplib2.socks.PROXY_TYPE_HTTP_NO_TUNNEL
        else:
            raise TypeError("unsupport type: %s" % proxy_info['type'])

        proxy = httplib2.ProxyInfo(proxy_type, proxy_info['host'], proxy_info['port'])
        client = httplib2.Http(proxy_info=proxy, timeout=25)
        return client
github jay0lee / got-your-back / httplib2 / __init__.py View on Github external
host = proxy_host
            port = proxy_port
        else:
            use_proxy = False

            host = self.host
            port = self.port
            proxy_type = None

        socket_err = None

        for res in socket.getaddrinfo(host, port, 0, socket.SOCK_STREAM):
            af, socktype, proto, canonname, sa = res
            try:
                if use_proxy:
                    self.sock = socks.socksocket(af, socktype, proto)
                    self.sock.setproxy(proxy_type, proxy_host, proxy_port, proxy_rdns, proxy_user, proxy_pass)
                else:
                    self.sock = socket.socket(af, socktype, proto)
                    self.sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
                if has_timeout(self.timeout):
                    self.sock.settimeout(self.timeout)
                if self.debuglevel > 0:
                    print(
                        "connect: ({0}, {1}) ************".format(self.host, self.port))
                    if use_proxy:
                        print(
                            "proxy: {0} ************".format(str(
                                (proxy_host, proxy_port, proxy_rdns, proxy_user, proxy_pass, proxy_headers))))

                self.sock.connect((self.host, self.port) + sa[2:])
            except socket.error as e:
github linkedin / iris-relay / src / iris_relay / gmail.py View on Github external
def __init__(self, config=None, proxy_config=None):
        self.config = config
        self.client = None
        if proxy_config and 'host' in proxy_config and 'port' in proxy_config:
            proxy_info = ProxyInfo(socks.PROXY_TYPE_HTTP_NO_TUNNEL,
                                   proxy_config['host'], proxy_config['port'])
        else:
            proxy_info = None
        self.http = Http(proxy_info=proxy_info)
        self.var_dir = self.config['var_dir']
        if not exists(self.var_dir):
            makedirs(self.var_dir)
        self.history_id_f = join(self.var_dir, 'gmail_last_history_id')
        if exists(self.history_id_f):
            with open(self.history_id_f) as fh:
                logger.info('Loaded last gmail history id %d', int(fh.read()))
        else:
            # store an invalid id, which will get renewed on next push event
            self.save_last_history_id('1')