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


Python http_client.BAD_REQUEST属性代码示例

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


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

示例1: do_GET

# 需要导入模块: from six.moves import http_client [as 别名]
# 或者: from six.moves.http_client import BAD_REQUEST [as 别名]
def do_GET(self):
            """
            Handle a ping request
            """
            if not self.path.endswith("/"): self.path += "/"
            if self.path == "/ping/":
                msg = "pong".encode("UTF-8")

                self.send_response(HTTPStatus.OK)
                self.send_header("Content-Type", "text/application")
                self.send_header("Content-Length", len(msg))
                self.end_headers()
                self.wfile.write(msg)
            else:
                self.send_response(HTTPStatus.BAD_REQUEST)
                self.end_headers() 
开发者ID:stanfordnlp,项目名称:python-stanford-corenlp,代码行数:18,代码来源:annotator.py

示例2: _test_bad_payload

# 需要导入模块: from six.moves import http_client [as 别名]
# 或者: from six.moves.http_client import BAD_REQUEST [as 别名]
def _test_bad_payload(self):
        response = self.app.post(
            '/runs',
            data=json.dumps(dict(inventory_file='localhost,',
                                 options={'connection': 'local'})),
            content_type='application/json')
        self.assertEqual(http_client.BAD_REQUEST, response.status_code)

        pb = 'tests/fixtures/playbooks/hello_world_with_fail.yml'
        response = self.app.post(
            '/runs',
            data=json.dumps(dict(playbook_path=pb,
                                 inventory_file='localhost,',
                                 options={'connection': 'local',
                                          'bad_option': 'bad'})),
            content_type='application/json')
        self.assertEqual(http_client.BAD_REQUEST, response.status_code) 
开发者ID:vmware-archive,项目名称:column,代码行数:19,代码来源:test_run.py

示例3: test__token_endpoint_request_internal_failure_error

# 需要导入模块: from six.moves import http_client [as 别名]
# 或者: from six.moves.http_client import BAD_REQUEST [as 别名]
def test__token_endpoint_request_internal_failure_error():
    request = make_request(
        {"error_description": "internal_failure"}, status=http_client.BAD_REQUEST
    )

    with pytest.raises(exceptions.RefreshError):
        _client._token_endpoint_request(
            request, "http://example.com", {"error_description": "internal_failure"}
        )

    request = make_request(
        {"error": "internal_failure"}, status=http_client.BAD_REQUEST
    )

    with pytest.raises(exceptions.RefreshError):
        _client._token_endpoint_request(
            request, "http://example.com", {"error": "internal_failure"}
        ) 
开发者ID:googleapis,项目名称:google-auth-library-python,代码行数:20,代码来源:test__client.py

示例4: test__process_recover_response_bad_status

# 需要导入模块: from six.moves import http_client [as 别名]
# 或者: from six.moves.http_client import BAD_REQUEST [as 别名]
def test__process_recover_response_bad_status(self):
        upload = _upload.ResumableUpload(RESUMABLE_URL, ONE_MB)
        _fix_up_virtual(upload)

        upload._invalid = True

        response = _make_response(status_code=http_client.BAD_REQUEST)
        with pytest.raises(common.InvalidResponse) as exc_info:
            upload._process_recover_response(response)

        error = exc_info.value
        assert error.response is response
        assert len(error.args) == 4
        assert error.args[1] == response.status_code
        assert error.args[3] == resumable_media.PERMANENT_REDIRECT
        # Make sure still invalid.
        assert upload.invalid 
开发者ID:googleapis,项目名称:google-resumable-media-python,代码行数:19,代码来源:test__upload.py

示例5: test_extra_headers

# 需要导入模块: from six.moves import http_client [as 别名]
# 或者: from six.moves.http_client import BAD_REQUEST [as 别名]
def test_extra_headers(self, authorized_transport, secret_file):
        blob_name, data, headers = secret_file
        # Create the actual download object.
        media_url = utils.DOWNLOAD_URL_TEMPLATE.format(blob_name=blob_name)
        download = self._make_one(media_url, headers=headers)
        # Consume the resource.
        response = download.consume(authorized_transport)
        assert response.status_code == http_client.OK
        assert response.content == data
        check_tombstoned(download, authorized_transport)
        # Attempt to consume the resource **without** the headers.
        download_wo = self._make_one(media_url)
        with pytest.raises(common.InvalidResponse) as exc_info:
            download_wo.consume(authorized_transport)

        check_error_response(exc_info, http_client.BAD_REQUEST, ENCRYPTED_ERR)
        check_tombstoned(download_wo, authorized_transport) 
开发者ID:googleapis,项目名称:google-resumable-media-python,代码行数:19,代码来源:test_download.py

示例6: check_validation_error

# 需要导入模块: from six.moves import http_client [as 别名]
# 或者: from six.moves.http_client import BAD_REQUEST [as 别名]
def check_validation_error(self, method, body, expected_detail, req=None):
        if not req:
            req = FakeRequest()
        try:
            method(body=body, req=req,)
        except exception.ValidationError as ex:
            self.assertEqual(http.BAD_REQUEST, ex.kwargs['code'])
            if isinstance(expected_detail, list):
                self.assertIn(ex.kwargs['detail'], expected_detail,
                              'Exception details did not match expected')
            elif not re.match(expected_detail, ex.kwargs['detail']):
                self.assertEqual(expected_detail, ex.kwargs['detail'],
                                 'Exception details did not match expected')
        except Exception as ex:
            self.fail('An unexpected exception happens: %s' % ex)
        else:
            self.fail('Any exception does not happen.') 
开发者ID:openstack,项目名称:masakari,代码行数:19,代码来源:test_api_validation.py

示例7: test_instantiate_with_non_existing_deployment_flavour

# 需要导入模块: from six.moves import http_client [as 别名]
# 或者: from six.moves.http_client import BAD_REQUEST [as 别名]
def test_instantiate_with_non_existing_deployment_flavour(
            self, mock_vnf_package_get_by_id, mock_vnf_package_vnfd_get_by_id,
            mock_vnf_instance_get_by_id):

        mock_vnf_instance_get_by_id.return_value =\
            fakes.return_vnf_instance_model()
        mock_vnf_package_vnfd_get_by_id.return_value = \
            fakes.return_vnf_package_vnfd()
        mock_vnf_package_get_by_id.return_value = \
            fakes.return_vnf_package_with_deployment_flavour()

        body = {"flavourId": "invalid"}
        req = fake_request.HTTPRequest.blank(
            '/vnf_instances/%s/instantiate' % uuidsentinel.vnf_instance_id)
        req.body = jsonutils.dump_as_bytes(body)
        req.headers['Content-Type'] = 'application/json'
        req.method = 'POST'

        # Call Instantiate API
        resp = req.get_response(self.app)
        self.assertEqual(http_client.BAD_REQUEST, resp.status_code)
        self.assertEqual("No flavour with id 'invalid'.",
            resp.json['badRequest']['message']) 
开发者ID:openstack,项目名称:tacker,代码行数:25,代码来源:test_controller.py

示例8: test_instantiate_with_non_existing_instantiation_level

# 需要导入模块: from six.moves import http_client [as 别名]
# 或者: from six.moves.http_client import BAD_REQUEST [as 别名]
def test_instantiate_with_non_existing_instantiation_level(
            self, mock_instantiate, mock_vnf_package_get_by_id,
            mock_vnf_package_vnfd_get_by_id,
            mock_vnf_instance_get_by_id):

        mock_vnf_instance_get_by_id.return_value =\
            fakes.return_vnf_instance_model()
        mock_vnf_package_vnfd_get_by_id.return_value = \
            fakes.return_vnf_package_vnfd()
        mock_vnf_package_get_by_id.return_value = \
            fakes.return_vnf_package_with_deployment_flavour()

        body = {"flavourId": "simple",
                "instantiationLevelId": "non-existing"}
        req = fake_request.HTTPRequest.blank(
            '/vnf_instances/%s/instantiate' % uuidsentinel.vnf_instance_id)
        req.body = jsonutils.dump_as_bytes(body)
        req.headers['Content-Type'] = 'application/json'
        req.method = 'POST'

        # Call Instantiate API
        resp = req.get_response(self.app)
        self.assertEqual(http_client.BAD_REQUEST, resp.status_code)
        self.assertEqual("No instantiation level with id 'non-existing'.",
            resp.json['badRequest']['message']) 
开发者ID:openstack,项目名称:tacker,代码行数:27,代码来源:test_controller.py

示例9: test_instantiate_with_default_vim_not_configured

# 需要导入模块: from six.moves import http_client [as 别名]
# 或者: from six.moves.http_client import BAD_REQUEST [as 别名]
def test_instantiate_with_default_vim_not_configured(
            self, mock_vnf_package_get_by_id, mock_vnf_package_vnfd_get_by_id,
            mock_vnf_instance_get_by_id, mock_get_vim):

        mock_vnf_instance_get_by_id.return_value =\
            fakes.return_vnf_instance_model()
        mock_vnf_package_vnfd_get_by_id.return_value = \
            fakes.return_vnf_package_vnfd()
        mock_vnf_package_get_by_id.return_value = \
            fakes.return_vnf_package_with_deployment_flavour()
        mock_get_vim.side_effect = nfvo.VimDefaultNotDefined

        body = {"flavourId": "simple"}
        req = fake_request.HTTPRequest.blank(
            '/vnf_instances/%s/instantiate' % uuidsentinel.vnf_instance_id)
        req.body = jsonutils.dump_as_bytes(body)
        req.headers['Content-Type'] = 'application/json'
        req.method = 'POST'

        # Call Instantiate API
        resp = req.get_response(self.app)
        self.assertEqual(http_client.BAD_REQUEST, resp.status_code)
        self.assertEqual("Default VIM is not defined.",
            resp.json['badRequest']['message']) 
开发者ID:openstack,项目名称:tacker,代码行数:26,代码来源:test_controller.py

示例10: test_heal_with_invalid_vnfc_id

# 需要导入模块: from six.moves import http_client [as 别名]
# 或者: from six.moves.http_client import BAD_REQUEST [as 别名]
def test_heal_with_invalid_vnfc_id(self, mock_vnf_by_id):
        vnf_instance_obj = fakes.return_vnf_instance(
            fields.VnfInstanceState.INSTANTIATED)
        mock_vnf_by_id.return_value = vnf_instance_obj

        body = {'vnfcInstanceId': [uuidsentinel.vnfc_instance_id]}
        req = fake_request.HTTPRequest.blank(
            '/vnf_instances/%s/heal' % uuidsentinel.vnf_instance_id)
        req.body = jsonutils.dump_as_bytes(body)
        req.headers['Content-Type'] = 'application/json'
        req.method = 'POST'

        resp = req.get_response(self.app)
        self.assertEqual(http_client.BAD_REQUEST, resp.status_code)
        expected_msg = "Vnfc id %s not present in vnf instance %s"
        self.assertEqual(expected_msg % (uuidsentinel.vnfc_instance_id,
            uuidsentinel.vnf_instance_id), resp.json['badRequest']['message']) 
开发者ID:openstack,项目名称:tacker,代码行数:19,代码来源:test_controller.py

示例11: handle_auth

# 需要导入模块: from six.moves import http_client [as 别名]
# 或者: from six.moves.http_client import BAD_REQUEST [as 别名]
def handle_auth(self, request, headers=None, remote_addr=None,
                    remote_user=None, authorization=None, **kwargs):
        remote_addr = headers.get('x-forwarded-for',
                                  remote_addr)
        extra = {'remote_addr': remote_addr}

        if remote_user:
            ttl = getattr(request, 'ttl', None)
            username = self._get_username_for_request(remote_user, request)
            try:
                token = self._create_token_for_user(username=username,
                                                    ttl=ttl)
            except TTLTooLargeException as e:
                abort_request(status_code=http_client.BAD_REQUEST,
                              message=six.text_type(e))
            return token

        LOG.audit('Access denied to anonymous user.', extra=extra)
        abort_request() 
开发者ID:StackStorm,项目名称:st2,代码行数:21,代码来源:handlers.py

示例12: test_put_sys_pack

# 需要导入模块: from six.moves import http_client [as 别名]
# 或者: from six.moves.http_client import BAD_REQUEST [as 别名]
def test_put_sys_pack(self):
        instance = self.__create_instance()
        instance['pack'] = 'core'

        post_resp = self.__do_post(instance)
        self.assertEqual(post_resp.status_int, http_client.CREATED)

        updated_input = post_resp.json
        updated_input['enabled'] = not updated_input['enabled']
        put_resp = self.__do_put(self.__get_obj_id(post_resp), updated_input)
        self.assertEqual(put_resp.status_int, http_client.BAD_REQUEST)
        self.assertEqual(put_resp.json['faultstring'],
                         "Resources belonging to system level packs can't be manipulated")

        # Clean up manually since API won't delete object in sys pack.
        Policy.delete(Policy.get_by_id(self.__get_obj_id(post_resp))) 
开发者ID:StackStorm,项目名称:st2,代码行数:18,代码来源:test_policies.py

示例13: test_respond_duplicate_rejected

# 需要导入模块: from six.moves import http_client [as 别名]
# 或者: from six.moves.http_client import BAD_REQUEST [as 别名]
def test_respond_duplicate_rejected(self):
        """Test that responding to an already-responded Inquiry fails
        """

        post_resp = self._do_create_inquiry(INQUIRY_2, RESULT_DEFAULT)
        inquiry_id = self._get_inquiry_id(post_resp)
        response = {"continue": True}
        put_resp = self._do_respond(inquiry_id, response)
        self.assertEqual(response, put_resp.json.get("response"))

        # The inquiry no longer exists, since the status should not be "pending"
        # Get the execution and confirm this.
        inquiry_execution = self._do_get_execution(inquiry_id)
        self.assertEqual(inquiry_execution.json.get('status'), 'succeeded')

        # A second, equivalent response attempt should not succeed, since the Inquiry
        # has already been successfully responded to
        put_resp = self._do_respond(inquiry_id, response, expect_errors=True)
        self.assertEqual(put_resp.status_int, http_client.BAD_REQUEST)
        self.assertIn('has already been responded to', put_resp.json['faultstring']) 
开发者ID:StackStorm,项目名称:st2,代码行数:22,代码来源:test_inquiries.py

示例14: testHttpError

# 需要导入模块: from six.moves import http_client [as 别名]
# 或者: from six.moves.http_client import BAD_REQUEST [as 别名]
def testHttpError(self):
        def fakeMakeRequest(*unused_args, **unused_kwargs):
            return http_wrapper.Response(
                info={'status': http_client.BAD_REQUEST},
                content='{"field": "abc"}',
                request_url='http://www.google.com')
        method_config = base_api.ApiMethodInfo(
            request_type_name='SimpleMessage',
            response_type_name='SimpleMessage')
        client = self.__GetFakeClient()
        service = FakeService(client=client)
        request = SimpleMessage()
        with mock(base_api.http_wrapper, 'MakeRequest', fakeMakeRequest):
            with self.assertRaises(exceptions.HttpBadRequestError) as err:
                service._RunMethod(method_config, request)
        http_error = err.exception
        self.assertEquals('http://www.google.com', http_error.url)
        self.assertEquals('{"field": "abc"}', http_error.content)
        self.assertEquals(method_config, http_error.method_config)
        self.assertEquals(request, http_error.request) 
开发者ID:google,项目名称:apitools,代码行数:22,代码来源:base_api_test.py

示例15: GetUserinfo

# 需要导入模块: from six.moves import http_client [as 别名]
# 或者: from six.moves.http_client import BAD_REQUEST [as 别名]
def GetUserinfo(credentials, http=None):  # pylint: disable=invalid-name
    """Get the userinfo associated with the given credentials.

    This is dependent on the token having either the userinfo.email or
    userinfo.profile scope for the given token.

    Args:
      credentials: (oauth2client.client.Credentials) incoming credentials
      http: (httplib2.Http, optional) http instance to use

    Returns:
      The email address for this token, or None if the required scopes
      aren't available.
    """
    http = http or httplib2.Http()
    url = _GetUserinfoUrl(credentials)
    # We ignore communication woes here (i.e. SSL errors, socket
    # timeout), as handling these should be done in a common location.
    response, content = http.request(url)
    if response.status == http_client.BAD_REQUEST:
        credentials.refresh(http)
        url = _GetUserinfoUrl(credentials)
        response, content = http.request(url)
    return json.loads(content or '{}')  # Save ourselves from an empty reply. 
开发者ID:google,项目名称:apitools,代码行数:26,代码来源:credentials_lib.py


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