• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python urllib3.make_headers函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: getFile

 def getFile(self, url):
     headers = urllib3.make_headers(
         keep_alive=True,
         user_agent='Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_3_2 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8H7 Safari/653.18.5',
         accept_encoding=True)
     r = self.pm.request('GET', url, headers=headers)
     if r.status != 200:
         self.error = 'Error downloading: %s, %s' % (r.status, url)
         print self.error
     return r.data
开发者ID:Beirdo,项目名称:KSV-HDS-Scripts,代码行数:10,代码来源:AdobeHDS.py


示例17: checkWeb

def checkWeb():
    for chat_id, v in links.items():
        for link in v:
            print('Checking ' + link + '...')
            pool = urllib3.PoolManager()
            header = urllib3.make_headers(user_agent='Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.6 Safari/537.36')
            r = pool.request('GET', link, headers=header)
            html = r.data.decode('shift-jis').encode('utf-8').decode('utf-8')
            #pprint(html)
            if search_str not in html:
                bot.sendMessage(chat_id, 'ALERT! Room available: ' + link)
开发者ID:anthonywong,项目名称:JalanTelegramBot,代码行数:11,代码来源:bot.py


示例18: __init__

    def __init__(self, pools_size=4, maxsize=4):
        # urllib3.PoolManager will pass all kw parameters to connectionpool
        # https://github.com/shazow/urllib3/blob/f9409436f83aeb79fbaf090181cd81b784f1b8ce/urllib3/poolmanager.py#L75
        # https://github.com/shazow/urllib3/blob/f9409436f83aeb79fbaf090181cd81b784f1b8ce/urllib3/connectionpool.py#L680
        # maxsize is the number of requests to host that are allowed in parallel
        # ca_certs vs cert_file vs key_file
        # http://stackoverflow.com/a/23957365/2985775

        # cert_reqs
        if Configuration().verify_ssl:
            cert_reqs = ssl.CERT_REQUIRED
        else:
            cert_reqs = ssl.CERT_NONE

        # ca_certs
        if Configuration().ssl_ca_cert:
            ca_certs = Configuration().ssl_ca_cert
        else:
            # if not set certificate file, use Mozilla's root certificates.
            ca_certs = certifi.where()

        # cert_file
        cert_file = Configuration().cert_file

        # key file
        key_file = Configuration().key_file

        if Configuration().proxy is not None:
            proxy = Configuration().proxy
            proxy_url = urllib3.util.parse_url(proxy)
            proxy_hostport = '{}://{}:{}'.format(proxy_url.scheme, proxy_url.host, proxy_url.port) if proxy_url.port else '{}://{}'.format(proxy_url.scheme, proxy_url.host)
            proxy_auth = urllib3.make_headers(proxy_basic_auth=proxy_url.auth) if proxy_url.auth else None

            self.pool_manager = urllib3.ProxyManager(
                num_pools=pools_size,
                maxsize=maxsize,
                cert_reqs=cert_reqs,
                ca_certs=ca_certs,
                cert_file=cert_file,
                key_file=key_file,
                proxy_url=proxy_hostport,
                proxy_headers=proxy_auth
            )
        else:
            self.pool_manager = urllib3.PoolManager(
                num_pools=pools_size,
                maxsize=maxsize,
                cert_reqs=cert_reqs,
                ca_certs=ca_certs,
                cert_file=cert_file,
                key_file=key_file
        )
开发者ID:EvidentSecurity,项目名称:esp-sdk-python,代码行数:52,代码来源:rest.py


示例19: __init__

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

        pool_class = urllib3.HTTPConnectionPool
        if use_ssl:
            pool_class = urllib3.HTTPSConnectionPool

        self.pool = pool_class(host, port=port, timeout=kwargs.get('timeout', None), headers=headers)
开发者ID:RonRothman,项目名称:elasticsearch-py,代码行数:13,代码来源:http_urllib3.py


示例20: __init__

 def __init__(self, servers=None, retry_time=60, max_retries=3, timeout=None,
              basic_auth=None):
     if servers is None:
         servers = [DEFAULT_SERVER]
     self._active_servers = [server.geturl() for server in servers]
     self._inactive_servers = []
     self._retry_time = retry_time
     self._max_retries = max_retries
     self._timeout = timeout
     if basic_auth:
         self._headers = urllib3.make_headers(basic_auth="%(username)s:%(password)s" % basic_auth)
     else:
         self._headers = {}
     self._lock = threading.RLock()
     self._local = threading.local()
开发者ID:0x64746b,项目名称:pyes,代码行数:15,代码来源:connection_http.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python urllib3.HTTPConnectionPool类代码示例发布时间:2022-05-27
下一篇:
Python urllib3.encode_multipart_formdata函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap