當前位置: 首頁>>代碼示例>>Python>>正文


Python urllib3.HTTPResponse方法代碼示例

本文整理匯總了Python中urllib3.HTTPResponse方法的典型用法代碼示例。如果您正苦於以下問題:Python urllib3.HTTPResponse方法的具體用法?Python urllib3.HTTPResponse怎麽用?Python urllib3.HTTPResponse使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在urllib3的用法示例。


在下文中一共展示了urllib3.HTTPResponse方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: get_urlopen_mock

# 需要導入模塊: import urllib3 [as 別名]
# 或者: from urllib3 import HTTPResponse [as 別名]
def get_urlopen_mock(body=DEFAULT_BODY_CONTENT, headers=None, status=200):
    mockHttpResponse = Mock(name='httplib.HTTPResponse')

    headers = urllib3.response.HTTPHeaderDict(headers)

    if not hasattr(body, 'read'):
        body = BytesIO(body)

    else:
        body.seek(0)

    urllib3_response = urllib3.HTTPResponse(body,
                                            headers,
                                            status,
                                            preload_content=False,
                                            original_response=mockHttpResponse)

    return MagicMock(return_value=urllib3_response) 
開發者ID:danpoland,項目名稱:drf-reverse-proxy,代碼行數:20,代碼來源:utils.py

示例2: _provide_ssl_auth_required

# 需要導入模塊: import urllib3 [as 別名]
# 或者: from urllib3 import HTTPResponse [as 別名]
def _provide_ssl_auth_required(self):
        """
        Provide ssl auth response
        :return: urllib3.HTTPResponse
        """
        
        response = HTTPResponse()
        response.status = self.DEFAULT_SSL_CERT_REQUIRED_STATUSES
        response.__setattr__('_body', ' ')
        return response 
開發者ID:stanislav-web,項目名稱:OpenDoor,代碼行數:12,代碼來源:https.py

示例3: json

# 需要導入模塊: import urllib3 [as 別名]
# 或者: from urllib3 import HTTPResponse [as 別名]
def json(self) -> Dict[str, Any]:
        """Convert the response data to JSON.

        If the response data is not valid JSON, an error will be raised.

        Returns:
            The JSON data loaded into a Python dictionary.
        """
        # This should generally be the case, since the primary source of Response
        # instances are the HTTP methods on Pods (e.g. http_proxy_get), where
        # `_preload_content=False`. Should that be set to True, it will not return
        # the HTTPResponse but will instead return the response data formatted as
        # the type specified in the `response_type` param. By default, kubetest sets
        # the _preload_content field to True, so this should generally not be hit.
        if isinstance(self.data, urllib3.HTTPResponse):
            return json.loads(self.data.data)

        # The response data comes back as a string. This could be a JSON string,
        # or something else (text body, error string, etc). Since we've preloaded
        # the content as a string (see comment above), we can not simply load the
        # string as JSON as the preloading essentially serializes the Python dict
        # out to a string, so various values will not parse into JSON (None vs null,
        # " vs ', etc). To remedy this, we attempt to load the response as an ast
        # literal - if it fails for any reason, fall back to trying to load JSON.
        # At the very least the JSON loading will fail with a familiar error which
        # one would expect from a .json() function.
        try:
            data = ast.literal_eval(self.data)
        except Exception as e:
            log.debug(f'failed literal eval of data {self.data} ({e})')
            data = json.loads(self.data)

        return data 
開發者ID:vapor-ware,項目名稱:kubetest,代碼行數:35,代碼來源:response.py

示例4: __init__

# 需要導入模塊: import urllib3 [as 別名]
# 或者: from urllib3 import HTTPResponse [as 別名]
def __init__(self, response: HTTPResponse, serialization_mode: FluxSerializationMode,
                 data_frame_index: List[str] = None) -> None:
        self._response = response
        self.tables = []
        self._serialization_mode = serialization_mode
        self._data_frame_index = data_frame_index
        self._data_frame_values = []
        pass 
開發者ID:influxdata,項目名稱:influxdb-client-python,代碼行數:10,代碼來源:flux_csv_parser.py

示例5: _parse_to_tables

# 需要導入模塊: import urllib3 [as 別名]
# 或者: from urllib3 import HTTPResponse [as 別名]
def _parse_to_tables(data: str):
        fp = BytesIO(str.encode(data))
        _parser = FluxCsvParser(response=HTTPResponse(fp, preload_content=False),
                                serialization_mode=FluxSerializationMode.tables)
        list(_parser.generator())
        tables = _parser.tables
        return tables 
開發者ID:influxdata,項目名稱:influxdb-client-python,代碼行數:9,代碼來源:test_FluxCSVParser.py

示例6: __init__

# 需要導入模塊: import urllib3 [as 別名]
# 或者: from urllib3 import HTTPResponse [as 別名]
def __init__(self, resp):
        # arg: A urllib3.HTTPResponse object
        self.urllib3_response = resp
        self.status = resp.status
        self.version = resp.version
        self.reason = resp.reason
        self.strict = resp.strict
        self.is_closed = False 
開發者ID:fniephaus,項目名稱:alfred-dropbox,代碼行數:10,代碼來源:rest.py

示例7: closed

# 需要導入模塊: import urllib3 [as 別名]
# 或者: from urllib3 import HTTPResponse [as 別名]
def closed(self):
        return self.is_closed


    # ---------------------------------
    # Backwards compat for HTTPResponse
    # --------------------------------- 
開發者ID:fniephaus,項目名稱:alfred-dropbox,代碼行數:9,代碼來源:rest.py

示例8: test_run_next_exception

# 需要導入模塊: import urllib3 [as 別名]
# 或者: from urllib3 import HTTPResponse [as 別名]
def test_run_next_exception(self, mock_get_kube_client, mock_kubernetes_job_watcher):

        # When a quota is exceeded this is the ApiException we get
        response = HTTPResponse(
            body='{"kind": "Status", "apiVersion": "v1", "metadata": {}, "status": "Failure", '
                 '"message": "pods \\"podname\\" is forbidden: exceeded quota: compute-resources, '
                 'requested: limits.memory=4Gi, used: limits.memory=6508Mi, limited: limits.memory=10Gi", '
                 '"reason": "Forbidden", "details": {"name": "podname", "kind": "pods"}, "code": 403}')
        response.status = 403
        response.reason = "Forbidden"

        # A mock kube_client that throws errors when making a pod
        mock_kube_client = mock.patch('kubernetes.client.CoreV1Api', autospec=True)
        mock_kube_client.create_namespaced_pod = mock.MagicMock(
            side_effect=ApiException(http_resp=response))
        mock_get_kube_client.return_value = mock_kube_client
        mock_api_client = mock.MagicMock()
        mock_api_client.sanitize_for_serialization.return_value = {}
        mock_kube_client.api_client = mock_api_client

        kubernetes_executor = KubernetesExecutor()
        kubernetes_executor.start()

        # Execute a task while the Api Throws errors
        try_number = 1
        kubernetes_executor.execute_async(key=('dag', 'task', datetime.utcnow(), try_number),
                                          queue=None,
                                          command=['airflow', 'tasks', 'run', 'true', 'some_parameter'],
                                          executor_config={})
        kubernetes_executor.sync()
        kubernetes_executor.sync()

        assert mock_kube_client.create_namespaced_pod.called
        self.assertFalse(kubernetes_executor.task_queue.empty())

        # Disable the ApiException
        mock_kube_client.create_namespaced_pod.side_effect = None

        # Execute the task without errors should empty the queue
        kubernetes_executor.sync()
        assert mock_kube_client.create_namespaced_pod.called
        self.assertTrue(kubernetes_executor.task_queue.empty()) 
開發者ID:apache,項目名稱:airflow,代碼行數:44,代碼來源:test_kubernetes_executor.py

示例9: request

# 需要導入模塊: import urllib3 [as 別名]
# 或者: from urllib3 import HTTPResponse [as 別名]
def request(self, url):
        """
        Client request SSL
        :param str url: request uri
        :return: urllib3.HTTPResponse
        """

        if self._HTTP_DBG_LEVEL <= self.__debug.level:
            self.__debug.debug_request(self._headers, url, self.__cfg.method)

        try:

            disable_warnings(InsecureRequestWarning)

            if self.__cfg.DEFAULT_SCAN == self.__cfg.scan:  # directories requests
                response = self.__pool.request(self.__cfg.method,
                                               helper.parse_url(url).path,
                                               headers=self._headers,
                                               retries=self.__cfg.retries,
                                               assert_same_host=False,
                                               redirect=False)
                self.cookies_middleware(is_accept=self.__cfg.accept_cookies, response=response)
            else:  # subdomains

                response = PoolManager().request(self.__cfg.method, url,
                                                 headers=self._headers,
                                                 retries=self.__cfg.retries,
                                                 assert_same_host=False,
                                                 redirect=False)
            return response

        except MaxRetryError:
            if self.__cfg.DEFAULT_SCAN == self.__cfg.scan:
                self.__tpl.warning(key='max_retry_error', url=helper.parse_url(url).path)

        except HostChangedError as error:
            self.__tpl.warning(key='host_changed_error', details=error)
            pass

        except ReadTimeoutError:
            self.__tpl.warning(key='read_timeout_error', url=url)
            pass

        except ConnectTimeoutError:
            self.__tpl.warning(key='connection_timeout_error', url=url)
            pass

        except SSLError:
            if self.__cfg.DEFAULT_SCAN != self.__cfg.scan:
                return self._provide_ssl_auth_required() 
開發者ID:stanislav-web,項目名稱:OpenDoor,代碼行數:52,代碼來源:https.py


注:本文中的urllib3.HTTPResponse方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。