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


Python client.BAD_REQUEST属性代码示例

本文整理汇总了Python中http.client.BAD_REQUEST属性的典型用法代码示例。如果您正苦于以下问题:Python client.BAD_REQUEST属性的具体用法?Python client.BAD_REQUEST怎么用?Python client.BAD_REQUEST使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在http.client的用法示例。


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

示例1: add

# 需要导入模块: from http import client [as 别名]
# 或者: from http.client import BAD_REQUEST [as 别名]
def add(self):
        try:
            params = self._prepare_request()
        except Exception:
            LOG.exception('Exception when reading CNI params.')
            return '', httplib.BAD_REQUEST, self.headers

        try:
            vif = self.plugin.add(params)
            data = jsonutils.dumps(vif.obj_to_primitive())
        except exception.ResourceNotReady:
            LOG.error('Error when processing addNetwork request')
            return '', httplib.GATEWAY_TIMEOUT, self.headers
        except Exception:
            LOG.exception('Error when processing addNetwork request. CNI '
                          'Params: %s', params)
            return '', httplib.INTERNAL_SERVER_ERROR, self.headers

        return data, httplib.ACCEPTED, self.headers 
开发者ID:openstack,项目名称:zun,代码行数:21,代码来源:service.py

示例2: delete

# 需要导入模块: from http import client [as 别名]
# 或者: from http.client import BAD_REQUEST [as 别名]
def delete(self):
        try:
            params = self._prepare_request()
        except Exception:
            LOG.exception('Exception when reading CNI params.')
            return '', httplib.BAD_REQUEST, self.headers

        try:
            self.plugin.delete(params)
        except exception.ResourceNotReady:
            # NOTE(dulek): It's better to ignore this error - most of the time
            #              it will happen when capsule is long gone and runtime
            #              overzealously tries to delete it from the network.
            #              We cannot really do anything without VIF metadata,
            #              so let's just tell runtime to move along.
            LOG.warning('Error when processing delNetwork request. '
                        'Ignoring this error, capsule is most likely gone')
            return '', httplib.NO_CONTENT, self.headers
        except Exception:
            LOG.exception('Error when processing delNetwork request. CNI '
                          'Params: %s.', params)
            return '', httplib.INTERNAL_SERVER_ERROR, self.headers
        return '', httplib.NO_CONTENT, self.headers 
开发者ID:openstack,项目名称:zun,代码行数:25,代码来源:service.py

示例3: add

# 需要导入模块: from http import client [as 别名]
# 或者: from http.client import BAD_REQUEST [as 别名]
def add(self):
        try:
            params = self._prepare_request()
        except Exception:
            self._check_failure()
            LOG.exception('Exception when reading CNI params.')
            return '', httplib.BAD_REQUEST, self.headers

        try:
            vif = self.plugin.add(params)
            data = jsonutils.dumps(vif.obj_to_primitive())
        except exceptions.ResourceNotReady:
            self._check_failure()
            LOG.error('Error when processing addNetwork request')
            return '', httplib.GATEWAY_TIMEOUT, self.headers
        except Exception:
            self._check_failure()
            LOG.exception('Error when processing addNetwork request. CNI '
                          'Params: %s', params)
            return '', httplib.INTERNAL_SERVER_ERROR, self.headers

        return data, httplib.ACCEPTED, self.headers 
开发者ID:openstack,项目名称:kuryr-kubernetes,代码行数:24,代码来源:service.py

示例4: delete

# 需要导入模块: from http import client [as 别名]
# 或者: from http.client import BAD_REQUEST [as 别名]
def delete(self):
        try:
            params = self._prepare_request()
        except Exception:
            LOG.exception('Exception when reading CNI params.')
            return '', httplib.BAD_REQUEST, self.headers

        try:
            self.plugin.delete(params)
        except exceptions.ResourceNotReady:
            # NOTE(dulek): It's better to ignore this error - most of the time
            #              it will happen when pod is long gone and CRI
            #              overzealously tries to delete it from the network.
            #              We cannot really do anything without VIF annotation,
            #              so let's just tell CRI to move along.
            LOG.warning('Error when processing delNetwork request. '
                        'Ignoring this error, pod is most likely gone')
            return '', httplib.NO_CONTENT, self.headers
        except Exception:
            self._check_failure()
            LOG.exception('Error when processing delNetwork request. CNI '
                          'Params: %s.', params)
            return '', httplib.INTERNAL_SERVER_ERROR, self.headers
        return '', httplib.NO_CONTENT, self.headers 
开发者ID:openstack,项目名称:kuryr-kubernetes,代码行数:26,代码来源:service.py

示例5: eject_media

# 需要导入模块: from http import client [as 别名]
# 或者: from http.client import BAD_REQUEST [as 别名]
def eject_media(self):
        """Detach remote media from virtual media

        After ejecting media inserted will be False and image_name will be
        empty.
        """
        try:
            target_uri = self._get_eject_media_element().target_uri
            self._conn.post(target_uri)
        except exceptions.HTTPError as response:
            # Some vendors like HPE iLO has this kind of implementation.
            # It needs to pass an empty dict.
            if response.status_code in (
                    http_client.UNSUPPORTED_MEDIA_TYPE,
                    http_client.BAD_REQUEST):
                self._conn.post(target_uri, data={})
        self.invalidate() 
开发者ID:openstack,项目名称:sushy,代码行数:19,代码来源:virtual_media.py

示例6: test_api_request_fails

# 需要导入模块: from http import client [as 别名]
# 或者: from http.client import BAD_REQUEST [as 别名]
def test_api_request_fails(self):
        # GIVEN
        current_process = ngrok.get_ngrok_process(pyngrok_config=self.pyngrok_config)
        bad_options = {
            "name": str(uuid.uuid4()),
            "addr": "8080",
            "proto": "invalid-proto"
        }

        # WHEN
        with self.assertRaises(PyngrokNgrokHTTPError) as cm:
            ngrok.api_request("{}/api/{}".format(current_process.api_url, "tunnels"), "POST", data=bad_options)

        # THEN
        self.assertEqual(StatusCodes.BAD_REQUEST, cm.exception.status_code)
        self.assertIn("invalid tunnel configuration", str(cm.exception))
        self.assertIn("protocol name", str(cm.exception)) 
开发者ID:alexdlaird,项目名称:pyngrok,代码行数:19,代码来源:test_ngrok.py

示例7: after

# 需要导入模块: from http import client [as 别名]
# 或者: from http.client import BAD_REQUEST [as 别名]
def after(self, state):
        # Omit empty body. Some errors may not have body at this level yet.
        if not state.response.body:
            return

        # Do nothing if there is no error.
        # Status codes in the range 200 (OK) to 399 (400 = BAD_REQUEST) are not
        # an error.
        if (http_client.OK <= state.response.status_int <
                http_client.BAD_REQUEST):
            return

        json_body = state.response.json
        # Do not remove traceback when traceback config is set
        if cfg.CONF.debug:
            return

        faultstring = json_body.get('faultstring')
        traceback_marker = 'Traceback (most recent call last):'
        if faultstring and traceback_marker in faultstring:
            # Cut-off traceback.
            faultstring = faultstring.split(traceback_marker, 1)[0]
            # Remove trailing newlines and spaces if any.
            json_body['faultstring'] = faultstring.rstrip()
            # Replace the whole json. Cannot change original one because it's
            # generated on the fly.
            state.response.json = json_body 
开发者ID:openstack,项目名称:watcher,代码行数:29,代码来源:hooks.py

示例8: test_register_node_all_params_required

# 需要导入模块: from http import client [as 别名]
# 或者: from http.client import BAD_REQUEST [as 别名]
def test_register_node_all_params_required(self):
        resp = self.client.get('/register?name=examplehost')
        self.assertEqual(resp.status_code, httplib.BAD_REQUEST)

        resp = self.client.get('/register?port=500')
        self.assertEqual(resp.status_code, httplib.BAD_REQUEST) 
开发者ID:Jahaja,项目名称:psdash,代码行数:8,代码来源:test_web.py

示例9: raise_for_response

# 需要导入模块: from http import client [as 别名]
# 或者: from http.client import BAD_REQUEST [as 别名]
def raise_for_response(method, url, response):
    """Raise a correct error class, if needed."""
    if response.status_code < http_client.BAD_REQUEST:
        return
    elif response.status_code == http_client.NOT_FOUND:
        raise ResourceNotFoundError(method, url, response)
    elif response.status_code == http_client.BAD_REQUEST:
        raise BadRequestError(method, url, response)
    elif response.status_code in (http_client.UNAUTHORIZED,
                                  http_client.FORBIDDEN):
        raise AccessError(method, url, response)
    elif response.status_code >= http_client.INTERNAL_SERVER_ERROR:
        raise ServerSideError(method, url, response)
    else:
        raise HTTPError(method, url, response) 
开发者ID:openstack,项目名称:sushy,代码行数:17,代码来源:exceptions.py

示例10: test_eject_media_pass_empty_dict_400

# 需要导入模块: from http import client [as 别名]
# 或者: from http.client import BAD_REQUEST [as 别名]
def test_eject_media_pass_empty_dict_400(self):
        target_uri = ("/redfish/v1/Managers/BMC/VirtualMedia/Floppy1/Actions"
                      "/VirtualMedia.EjectMedia")
        self.conn.post.side_effect = [exceptions.HTTPError(
            method='POST', url=target_uri, response=mock.MagicMock(
                status_code=http_client.BAD_REQUEST)), '200']
        self.sys_virtual_media.eject_media()
        post_calls = [
            mock.call(target_uri),
            mock.call(target_uri, data={})]
        self.sys_virtual_media._conn.post.assert_has_calls(post_calls)
        self.assertTrue(self.sys_virtual_media._is_stale) 
开发者ID:openstack,项目名称:sushy,代码行数:14,代码来源:test_virtual_media.py

示例11: test_known_http_error

# 需要导入模块: from http import client [as 别名]
# 或者: from http.client import BAD_REQUEST [as 别名]
def test_known_http_error(self):
        self.request.return_value.status_code = http_client.BAD_REQUEST
        with open('sushy/tests/unit/json_samples/error.json') as f:
            self.request.return_value.json.return_value = json.load(f)

        with self.assertRaisesRegex(exceptions.BadRequestError,
                                    'body submitted was malformed JSON') as cm:
            self.conn._op('GET', 'http://foo.bar')
        exc = cm.exception
        self.assertEqual(http_client.BAD_REQUEST, exc.status_code)
        self.assertIsNotNone(exc.body)
        self.assertIn('body submitted was malformed JSON', exc.detail) 
开发者ID:openstack,项目名称:sushy,代码行数:14,代码来源:test_connector.py


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