当前位置: 首页>>代码示例>>Python>>正文


Python urllib3.make_headers函数代码示例

本文整理汇总了Python中urllib3.make_headers函数的典型用法代码示例。如果您正苦于以下问题:Python make_headers函数的具体用法?Python make_headers怎么用?Python make_headers使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了make_headers函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

    def __init__(self, host='localhost', port=9200, http_auth=None,
            use_ssl=False, verify_certs=False, ca_certs=None, client_cert=None,
            ssl_version=None, ssl_assert_hostname=None, ssl_assert_fingerprint=None,
            maxsize=10, **kwargs):

        super(Urllib3HttpConnection, self).__init__(host=host, port=port, **kwargs)
        self.headers = urllib3.make_headers(keep_alive=True)
        if http_auth is not None:
            if isinstance(http_auth, (tuple, list)):
                http_auth = ':'.join(http_auth)
            self.headers.update(urllib3.make_headers(basic_auth=http_auth))

        pool_class = urllib3.HTTPConnectionPool
        kw = {}
        if use_ssl:
            pool_class = urllib3.HTTPSConnectionPool
            kw.update({
                'ssl_version': ssl_version,
                'assert_hostname': ssl_assert_hostname,
                'assert_fingerprint': ssl_assert_fingerprint,
            })

            if verify_certs:
                kw.update({
                    'cert_reqs': 'CERT_REQUIRED',
                    'ca_certs': ca_certs,
                    'cert_file': client_cert,
                })
            elif ca_certs:
                raise ImproperlyConfigured("You cannot pass CA certificates when verify SSL is off.")
            else:
                warnings.warn(
                    'Connecting to %s using SSL with verify_certs=False is insecure.' % host)

        self.pool = pool_class(host, port=port, timeout=self.timeout, maxsize=maxsize, **kw)
开发者ID:ak795,项目名称:HCKERTH,代码行数:35,代码来源:http_urllib3.py

示例2: __init__

    def __init__(self):
        super(MovieCrawlerCP, self).__init__(cadena=u"Cineplanet", tag="CP")
        

        
        # indicadores de subtitulos
        self.suffix_subtitles['doblada'] =  [ 
            u'2D Doblada', 
            u'3D Doblada', 
            u'Doblada',
        ]

        self.suffix_subtitles['subtitluada'] = [
                u'Subtitulada', u'2D Subtitulada',
                u'3D Subtitulada',
            ]

        # indicadores de resolución
        self.suffix_resolutions['HD'] = [ u'Digital', u'Digital Hd', u'HD', u'Hd',  ]
        self.suffix_resolutions['3D'] = [ u'3D', ]
        
        self.suffix_discard = [  ]
        
                
        self.url = r"""https://cineplanet.com.pe"""
        self.encoding = 'utf-8'
        
        
        urllib3.make_headers(user_agent=wanderer())
        
        self.conn = urllib3.connectionpool.connection_from_url(
            self.url, 
            timeout=self.timeout,
            headers=wanderer()
        )
开发者ID:robertozoia,项目名称:cartelera,代码行数:35,代码来源:moviecrawler.py

示例3: upload

def upload():
    upload_url = "http://127.0.0.1:8080/upload"
    url = urllib3.util.parse_url(upload_url)
    cb_url = url.request_uri
     
    if url.port is not None:
        server = "%s:%d"%(url.host, url.port)            
    else:
        server = url.host
     
    conn = urllib3.connection_from_url(server)
    headers = urllib3.make_headers(keep_alive=True)
    content = "hello world"
    response = conn.urlopen("POST", cb_url, body=content, headers=headers)
    if response.status != 200:
        print "eeeeeeeeeeee"
        sys.exit(1)
    else:
        print response.getheaders()
        print response.read()
        print response.data
        fileid = json.loads(response.data)["fileid"]
     
    path = "/download?fileid=%d"%fileid
    print "download path:", path
    response = conn.urlopen("GET", path, headers=headers)
    if response.status != 200:
        print "download fail"
        sys.exit(1)
    else:
        print response.data
开发者ID:richmonkey,项目名称:haystack,代码行数:31,代码来源:upload.py

示例4: __init__

    def __init__(self, host='localhost', port=9200, http_auth=None,
            use_ssl=False, verify_certs=False, ca_certs=None, client_cert=None,
            maxsize=10, **kwargs):

        super(Urllib3HttpConnection, self).__init__(host=host, port=port, **kwargs)
        self.headers = {}
        if http_auth is not None:
            if isinstance(http_auth, (tuple, list)):
                http_auth = ':'.join(http_auth)
            self.headers = urllib3.make_headers(basic_auth=http_auth)

        pool_class = urllib3.HTTPConnectionPool
        kw = {}
        if use_ssl:
            pool_class = urllib3.HTTPSConnectionPool

            if verify_certs:
                kw['cert_reqs'] = 'CERT_REQUIRED'
                kw['ca_certs'] = ca_certs
                kw['cert_file'] = client_cert
            elif ca_certs:
                raise ImproperlyConfigured("You cannot pass CA certificates when verify SSL is off.")
            else:
                warnings.warn(
                    'Connecting to %s using SSL with verify_certs=False is insecure.' % host)

        self.pool = pool_class(host, port=port, timeout=self.timeout, maxsize=maxsize, **kw)
开发者ID:CCoffie,项目名称:elasticsearch-py,代码行数:27,代码来源:http_urllib3.py

示例5: _create_headers

 def _create_headers(self, content_type):
     """
     Creates the headers for the request.
     """
     headers = urllib3.make_headers(keep_alive=True)
     headers['content-type'] = content_type
     return headers
开发者ID:mgarski,项目名称:stellr,代码行数:7,代码来源:stellr.py

示例6: __init__

    def __init__(self, con_pool_size=1, proxy_url=None, urllib3_proxy_kwargs=None):
        if urllib3_proxy_kwargs is None:
            urllib3_proxy_kwargs = dict()

        kwargs = dict(
            maxsize=con_pool_size,
            cert_reqs="CERT_REQUIRED",
            ca_certs=certifi.where(),
            socket_options=HTTPConnection.default_socket_options + [(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)],
        )

        # Set a proxy according to the following order:
        # * proxy defined in proxy_url (+ urllib3_proxy_kwargs)
        # * proxy set in `HTTPS_PROXY` env. var.
        # * proxy set in `https_proxy` env. var.
        # * None (if no proxy is configured)

        if not proxy_url:
            proxy_url = os.environ.get("HTTPS_PROXY") or os.environ.get("https_proxy")

        if not proxy_url:
            mgr = urllib3.PoolManager(**kwargs)
        else:
            kwargs.update(urllib3_proxy_kwargs)
            mgr = urllib3.proxy_from_url(proxy_url, **kwargs)
            if mgr.proxy.auth:
                # TODO: what about other auth types?
                auth_hdrs = urllib3.make_headers(proxy_basic_auth=mgr.proxy.auth)
                mgr.proxy_headers.update(auth_hdrs)

        self._con_pool = mgr
开发者ID:python-telegram-bot,项目名称:python-telegram-bot,代码行数:31,代码来源:request.py

示例7: connect_web

def connect_web(url):
    try:
        http = urllib3.PoolManager()
        http.headers = urllib3.make_headers(user_agent=None)
        html = http.urlopen('GET', url)
        return html
    except ValueError:
        print("{}... does not exist..".format(url))
开发者ID:actionfiguredaniel,项目名称:eventall,代码行数:8,代码来源:seattle_events.py

示例8: getHTML

def getHTML(path):
    try:
        headers = urllib3.make_headers(keep_alive=True,user_agent="Microsoft-Windows/6.3 UPnP/1.0")
        http=urllib3.PoolManager(timeout=3.0)
        connection=http.request('get',path,headers=headers)
        return connection
    except:
        return None
开发者ID:hiEntropy,项目名称:webtools,代码行数:8,代码来源:webtools.py

示例9: __init__

    def __init__(self, host='localhost', port=9200, http_auth=None,
            use_ssl=False, verify_certs=True, ca_certs=None, client_cert=None,
            client_key=None, ssl_version=None, ssl_assert_hostname=None,
            ssl_assert_fingerprint=None, maxsize=10, headers=None, **kwargs):

        super(Urllib3HttpConnection, self).__init__(host=host, port=port, use_ssl=use_ssl, **kwargs)
        self.headers = urllib3.make_headers(keep_alive=True)
        if http_auth is not None:
            if isinstance(http_auth, (tuple, list)):
                http_auth = ':'.join(http_auth)
            self.headers.update(urllib3.make_headers(basic_auth=http_auth))

        # update headers in lowercase to allow overriding of auth headers
        if headers:
            for k in headers:
                self.headers[k.lower()] = headers[k]

        self.headers.setdefault('content-type', 'application/json')
        ca_certs = CA_CERTS if ca_certs is None else ca_certs
        pool_class = urllib3.HTTPConnectionPool
        kw = {}
        if use_ssl:
            pool_class = urllib3.HTTPSConnectionPool
            kw.update({
                'ssl_version': ssl_version,
                'assert_hostname': ssl_assert_hostname,
                'assert_fingerprint': ssl_assert_fingerprint,
            })

            if verify_certs:
                if not ca_certs:
                    raise ImproperlyConfigured("Root certificates are missing for certificate "
                        "validation. Either pass them in using the ca_certs parameter or "
                        "install certifi to use it automatically.")

                kw.update({
                    'cert_reqs': 'CERT_REQUIRED',
                    'ca_certs': ca_certs,
                    'cert_file': client_cert,
                    'key_file': client_key,
                })
            else:
                warnings.warn(
                    'Connecting to %s using SSL with verify_certs=False is insecure.' % host)

        self.pool = pool_class(host, port=port, timeout=self.timeout, maxsize=maxsize, **kw)
开发者ID:graemechristie,项目名称:consulkvbeat,代码行数:46,代码来源:http_urllib3.py

示例10: get_programacion_cine

    def get_programacion_cine(self, idCine=0, url=None):

        retries = 3
        while retries > 0:

            try:
                r = self.conn.request(
                    'GET', 
                    url,
                    headers = urllib3.make_headers(user_agent=wanderer())
                )
                break
            except TimeoutError:
                retries = retries - 1

        if retries > 0:

            if r.status == 200:
                html = r.data.decode(self.encoding, errors='replace')
                soup = BeautifulSoup(html)

                m_titles = [m.a.string.strip() for m in soup.find_all(
                    'div', class_='titcarte') if m.a]

                m_showtimes = []

                for m in soup.find_all('div', class_='horasprof'):
                    if m.string:
                        m_showtimes.append(m.string.strip())
                    else:
                        m_showtimes.append(None)

                movies = []


                for i in range(0, len(m_titles)):
                    # This is to handle case when no showtimes available for movie
                    if m_showtimes[i]:
                        movie = Movie(
                                name = self.purify_movie_name(m_titles[i]),
                                showtimes = self.grab_horarios(m_showtimes[i]),
                                # La página web de Cinerama no da mayor información
                                isSubtitled = True,
                                isTranslated = False,
                                isHD = True,
                                is3D = False,
                                isDbox = False,
                        )

                        movies.append(movie)

                return movies

            else:
                return []
        else:

            return []
开发者ID:robertozoia,项目名称:cartelera,代码行数:58,代码来源:moviecrawler.py

示例11: __make_headers

 def __make_headers(self, **header_kw):
     user = header_kw.get('user') or self.user
     password = header_kw.get('pass') or self.password
     proxy_user = header_kw.get('proxy_user') or self.proxy_user
     proxy_password = header_kw.get('proxy_pass') or self.proxy_password
     header_params = dict(keep_alive=True)
     proxy_header_params = dict()
     if user and password:
         header_params['basic_auth'] = '{user}:{password}'.format(user=user,
                                                                  password=password)
     if proxy_user and proxy_password:
         proxy_header_params['proxy_basic_auth'] = '{user}:{password}'.format(user=proxy_user,
                                                                              password=proxy_password)
     try:
         return urllib3.make_headers(**header_params), urllib3.make_headers(**proxy_header_params)
     except TypeError as error:
         self.error('build_header() error: {error}'.format(error=error))
         return None, None
开发者ID:dvigne,项目名称:netdata,代码行数:18,代码来源:base.py

示例12: _init_http_proxy

 def _init_http_proxy(self, http_proxy, **kwargs):
     pool_options = dict(kwargs)
     p = urlparse.urlparse(http_proxy)
     scheme = p.scheme
     netloc = p.netloc
     if "@" in netloc:
         auth, netloc = netloc.split("@", 2)
         pool_options["proxy_headers"] = urllib3.make_headers(proxy_basic_auth=auth)
     return urllib3.ProxyManager("%s://%s" % (scheme, netloc), **pool_options)
开发者ID:treasure-data,项目名称:td-client-python,代码行数:9,代码来源:api.py

示例13: _call_api

def _call_api(method, uri, params=None, body=None, headers=None, **options):
    prefix = options.pop("upload_prefix",
                         cloudinary.config().upload_prefix) or "https://api.cloudinary.com"
    cloud_name = options.pop("cloud_name", cloudinary.config().cloud_name)
    if not cloud_name:
        raise Exception("Must supply cloud_name")
    api_key = options.pop("api_key", cloudinary.config().api_key)
    if not api_key:
        raise Exception("Must supply api_key")
    api_secret = options.pop("api_secret", cloudinary.config().api_secret)
    if not cloud_name:
        raise Exception("Must supply api_secret")
    api_url = "/".join([prefix, "v1_1", cloud_name] + uri)

    processed_params = None
    if isinstance(params, dict):
        processed_params = {}
        for key, value in params.items():
            if isinstance(value, list) or isinstance(value, tuple):
                value_list = {"{}[{}]".format(key, i): i_value for i, i_value in enumerate(value)}
                processed_params.update(value_list)
            elif value:
                processed_params[key] = value

    # Add authentication
    req_headers = urllib3.make_headers(
        basic_auth="{0}:{1}".format(api_key, api_secret),
        user_agent=cloudinary.get_user_agent()
    )
    if headers is not None:
        req_headers.update(headers)
    kw = {}
    if 'timeout' in options:
        kw['timeout'] = options['timeout']
    if body is not None:
        kw['body'] = body
    try:
        response = _http.request(method.upper(), api_url, processed_params, req_headers, **kw)
        body = response.data
    except HTTPError as e:
        raise GeneralError("Unexpected error {0}", e.message)
    except socket.error as e:
        raise GeneralError("Socket Error: %s" % (str(e)))

    try:
        result = json.loads(body.decode('utf-8'))
    except Exception as e:
        # Error is parsing json
        raise GeneralError("Error parsing server response (%d) - %s. Got - %s" % (response.status, body, e))

    if "error" in result:
        exception_class = EXCEPTION_CODES.get(response.status) or Exception
        exception_class = exception_class
        raise exception_class("Error {0} - {1}".format(response.status, result["error"]["message"]))

    return Response(result, response)
开发者ID:cloudinary,项目名称:pycloudinary,代码行数:56,代码来源:api.py

示例14: response

 def response(self):
     if not self._response:
         # TODO: implement caching layer
         headers = urllib3.make_headers(accept_encoding=True)
         http = urllib3.PoolManager()
         self._response = http.request('GET', self.url, headers=headers)
         for line in str(self._response.data, encoding="utf-8").split('\n'):
             line = line.strip()
             if line:
                 yield line
开发者ID:mruser,项目名称:cloud_images,代码行数:10,代码来源:query.py

示例15: getFile

 def getFile(self, url):
     headers = urllib3.make_headers(
         keep_alive=True,
         user_agent='Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:17.0) Gecko/20100101 Firefox/17.0',
         accept_encoding=True)
     r = self.pm.request('GET', url, headers=headers)
     if r.status != 200:
         print 'Error downloading', r.status, url
         # sys.exit(1)
     return r.data
开发者ID:fbturk,项目名称:Scripts,代码行数:10,代码来源:AdobeHDS.py


注:本文中的urllib3.make_headers函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。