Python http.client.NOT_FOUND Examples
The following are 19
code examples of http.client.NOT_FOUND().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
http.client
, or try the search function
.
Example #1
Source File: third_party.py From CPU-Manager-for-Kubernetes with Apache License 2.0 | 6 votes |
def save(self): try: self.create() except K8sApiException as e: if e.status == client.NOT_FOUND: logging.warning("Third Party Resource is not ready yet. " "Report will be skipped") return if e.status == client.METHOD_NOT_ALLOWED: logging.error("API is blocked. Report will be skipped") return if e.status != client.CONFLICT: raise e logging.info("Previous resource has been detected. Recreating...") try: self.remove() except K8sApiException as e: if e.status != client.NOT_FOUND: raise e self.create()
Example #2
Source File: custom_resource.py From CPU-Manager-for-Kubernetes with Apache License 2.0 | 6 votes |
def save(self): """Save custom object if not exists""" try: self.create() except K8sApiException as e: if e.status == client.NOT_FOUND: logging.warning("Custom Resource Definition is not ready yet. " "Report will be skipped") return if e.status == client.METHOD_NOT_ALLOWED: logging.error("API is blocked. Report will be skipped") return if e.status != client.CONFLICT: raise e logging.warning("Previous definition has been detected. " "Recreating...") try: self.remove() except K8sApiException as e: if e.status != client.NOT_FOUND: raise e self.create()
Example #3
Source File: test_third_party.py From CPU-Manager-for-Kubernetes with Apache License 2.0 | 6 votes |
def test_third_party_resource_save_tpr_not_ready_failure(caplog): fake_http_resp = FakeHTTPResponse(client.NOT_FOUND, "fake reason", "fake body") fake_api_exception = K8sApiException(http_resp=fake_http_resp) mock = MagicMock() with patch('intel.k8s.extensions_client_from_config', MagicMock(return_value=mock)): fake_tpr = FakeTPR.generate_tpr() mock_create = MagicMock(side_effect=fake_api_exception) with patch('intel.third_party.ThirdPartyResource.create', mock_create): fake_tpr.save() assert mock_create.called exp_log_err = ("Third Party Resource is not ready yet. " "Report will be skipped") caplog_tuple = caplog.record_tuples assert caplog_tuple[-1][2] == exp_log_err
Example #4
Source File: middlewares.py From zentral with Apache License 2.0 | 6 votes |
def csp_middleware(get_response): def middleware(request): nonce_func = partial(make_csp_nonce, request) request.csp_nonce = SimpleLazyObject(nonce_func) response = get_response(request) if CSP_HEADER in response: # header already present (HOW ???) return response if response.status_code in (INTERNAL_SERVER_ERROR, NOT_FOUND) and settings.DEBUG: # no policies in debug views return response response[CSP_HEADER] = build_csp_header(request) return response return middleware
Example #5
Source File: test_connector.py From sushy with Apache License 2.0 | 5 votes |
def test_not_found_error(self): self.request.return_value.status_code = http_client.NOT_FOUND self.request.return_value.json.side_effect = ValueError('no json') with self.assertRaisesRegex(exceptions.ResourceNotFoundError, 'Resource http://foo.bar not found') as cm: self.conn._op('GET', 'http://foo.bar') exc = cm.exception self.assertEqual(http_client.NOT_FOUND, exc.status_code)
Example #6
Source File: health.py From kuryr-kubernetes with Apache License 2.0 | 5 votes |
def readiness_status(self): data = 'ok' if CONF.kubernetes.vif_pool_driver != 'noop': if not os.path.exists('/tmp/pools_loaded'): error_message = 'Ports not loaded into the pools.' LOG.error(error_message) return error_message, httplib.NOT_FOUND, self.headers k8s_conn = self.verify_k8s_connection() if not k8s_conn: error_message = 'Error when processing k8s healthz request.' LOG.error(error_message) return error_message, httplib.INTERNAL_SERVER_ERROR, self.headers try: self.verify_keystone_connection() except Exception as ex: error_message = ('Error when creating a Keystone session and ' 'getting a token: %s.' % ex) LOG.exception(error_message) return error_message, httplib.INTERNAL_SERVER_ERROR, self.headers try: if not self._components_ready(): return '', httplib.INTERNAL_SERVER_ERROR, self.headers except Exception as ex: error_message = ('Error when processing neutron request %s' % ex) LOG.exception(error_message) return error_message, httplib.INTERNAL_SERVER_ERROR, self.headers LOG.info('Kuryr Controller readiness verified.') return data, httplib.OK, self.headers
Example #7
Source File: test_base.py From sushy with Apache License 2.0 | 5 votes |
def test_get_member_for_invalid_id(self): # | GIVEN | # setting a valid member identity self.test_resource_collection.members_identities = ('1',) self.conn.get.side_effect = exceptions.ResourceNotFoundError( method='GET', url='http://foo.bar:8000/redfish/v1/Fakes/2', response=mock.MagicMock(status_code=http_client.NOT_FOUND)) # | WHEN & THEN | self.assertRaises(exceptions.ResourceNotFoundError, self.test_resource_collection.get_member, '2') self.conn.get.assert_called_once_with(path='Fakes/2')
Example #8
Source File: exceptions.py From sushy with Apache License 2.0 | 5 votes |
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)
Example #9
Source File: auth.py From flytekit with Apache License 2.0 | 5 votes |
def do_GET(self): url = _urlparse.urlparse(self.path) if url.path == self.server.redirect_path: self.send_response(_StatusCodes.OK) self.end_headers() self.handle_login(dict(_urlparse.parse_qsl(url.query))) else: self.send_response(_StatusCodes.NOT_FOUND)
Example #10
Source File: test_web.py From psdash with Creative Commons Zero v1.0 Universal | 5 votes |
def test_non_existing_file(self): filename = "/var/log/surelynotaroundright.log" resp = self.client.get('/log?filename=%s' % filename) self.assertEqual(resp.status_code, httplib.NOT_FOUND) resp = self.client.get('/log/search?filename=%s&text=%s' % (filename, 'something')) self.assertEqual(resp.status_code, httplib.NOT_FOUND) resp = self.client.get('/log/read?filename=%s' % filename) self.assertEqual(resp.status_code, httplib.NOT_FOUND) resp = self.client.get('/log/read_tail?filename=%s' % filename) self.assertEqual(resp.status_code, httplib.NOT_FOUND)
Example #11
Source File: test_web.py From psdash with Creative Commons Zero v1.0 Universal | 5 votes |
def test_non_existing(self): resp = self.client.get('/prettywronghuh') self.assertEqual(resp.status_code, httplib.NOT_FOUND)
Example #12
Source File: test_web.py From psdash with Creative Commons Zero v1.0 Universal | 5 votes |
def test_process_invalid_section(self): resp = self.client.get('/process/%d/whatnot' % self.pid) self.assertEqual(resp.status_code, httplib.NOT_FOUND)
Example #13
Source File: test_web.py From psdash with Creative Commons Zero v1.0 Universal | 5 votes |
def test_process_non_existing_pid(self): resp = self.client.get('/process/0') self.assertEqual(resp.status_code, httplib.NOT_FOUND)
Example #14
Source File: test_web.py From psdash with Creative Commons Zero v1.0 Universal | 5 votes |
def test_page_not_found_on_root(self): r = PsDashRunner({'PSDASH_URL_PREFIX': self.default_prefix}) resp = r.app.test_client().get('/') self.assertEqual(resp.status_code, httplib.NOT_FOUND)
Example #15
Source File: test_third_party.py From CPU-Manager-for-Kubernetes with Apache License 2.0 | 5 votes |
def test_third_party_resource_type_exists_success2(): fake_http_resp = FakeHTTPResponse(client.NOT_FOUND, "fake reason", "fake body") fake_api_exception = K8sApiException(http_resp=fake_http_resp) assert fake_api_exception.status == client.NOT_FOUND mock = MagicMock() with patch('intel.k8s.extensions_client_from_config', MagicMock(return_value=mock)): fake_type = FakeTPR.generate_tpr_type() mock.api_client.call_api = MagicMock(side_effect=fake_api_exception) exists = fake_type.exists() assert not exists
Example #16
Source File: test_custom_resource.py From CPU-Manager-for-Kubernetes with Apache License 2.0 | 5 votes |
def test_custom_resource_type_exists_success2(): fake_http_resp = FakeHTTPResponse(client.NOT_FOUND, "fake reason", "fake body") fake_api_exception = K8sApiException(http_resp=fake_http_resp) assert fake_api_exception.status == client.NOT_FOUND mock = MagicMock() with patch('intel.k8s.extensions_client_from_config', MagicMock(return_value=mock)): fake_type = FakeCRD.generate_crd_type() mock.api_client.call_api = MagicMock(side_effect=fake_api_exception) exists = fake_type.exists() assert not exists
Example #17
Source File: custom_resource.py From CPU-Manager-for-Kubernetes with Apache License 2.0 | 5 votes |
def exists(self, namespace="default"): """Check if custom resource definition exists""" try: self.api.api_client.call_api( self.resource_path_crd_type, 'GET', self.header_params, auth_settings=self.auth_settings) except K8sApiException as e: if e.status == client.CONFLICT or e.status == client.NOT_FOUND: return False raise e return True
Example #18
Source File: third_party.py From CPU-Manager-for-Kubernetes with Apache License 2.0 | 5 votes |
def exists(self, namespace="default"): header_params = { 'Content-Type': "application/json", 'Accept': "application/json" } auth_settings = ['BearerToken'] resource_path = "/".join([ "/apis", self.type_url, self.type_version, "namespaces", namespace, self.type_name + "s" ]) try: self.api.api_client.call_api( resource_path, 'GET', header_params, auth_settings=auth_settings) except K8sApiException as e: if e.status == client.CONFLICT or e.status == client.NOT_FOUND: return False raise e return True
Example #19
Source File: gcs_config.py From gokart with MIT License | 5 votes |
def get_gcs_client(self) -> luigi.contrib.gcs.GCSClient: if (not os.path.isfile(self.discover_cache_local_path)): with open(self.discover_cache_local_path, "w") as f: try: fcntl.flock(f, fcntl.LOCK_EX | fcntl.LOCK_NB) params = {"api": "storage", "apiVersion": "v1"} discovery_http = build_http() for discovery_url in (self._DISCOVERY_URI, self._V2_DISCOVERY_URI): requested_url = uritemplate.expand(discovery_url, params) try: content = _retrieve_discovery_doc( requested_url, discovery_http, False ) except HttpError as e: if e.resp.status == http_client.NOT_FOUND: continue else: raise e break f.write(content) fcntl.flock(f, fcntl.LOCK_UN) except IOError: # try to read pass with open(self.discover_cache_local_path, "r") as f: fcntl.flock(f, fcntl.LOCK_SH) descriptor = f.read() fcntl.flock(f, fcntl.LOCK_UN) return luigi.contrib.gcs.GCSClient(oauth_credentials=self._load_oauth_credentials(), descriptor=descriptor)