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


Python HTTPStatus.NOT_FOUND屬性代碼示例

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


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

示例1: get_swagger_doc

# 需要導入模塊: from http import HTTPStatus [as 別名]
# 或者: from http.HTTPStatus import NOT_FOUND [as 別名]
def get_swagger_doc(cls, http_method):
        """
            Create a swagger api model based on the sqlalchemy schema
            if an instance exists in the DB, the first entry is used as example
        """
        body = {}
        responses = {}
        object_name = cls.__name__
        object_model = {}
        responses = {HTTPStatus.OK.value: {"description": "{} object".format(object_name), "schema": object_model}}

        if http_method.upper() in ("POST", "GET"):
            responses = {
                HTTPStatus.OK.value: {"description": HTTPStatus.OK.description},
                HTTPStatus.NOT_FOUND.value: {"description": HTTPStatus.NOT_FOUND.description},
            }

        return body, responses 
開發者ID:thomaxxl,項目名稱:safrs,代碼行數:20,代碼來源:jsonapi.py

示例2: delete

# 需要導入模塊: from http import HTTPStatus [as 別名]
# 或者: from http.HTTPStatus import NOT_FOUND [as 別名]
def delete(self, params, msg):
        url = self.mothership_url + params
        headers = {"Accept": "application/json"}
        self.add_auth_header(headers)

        if self.verbose:
            req = requests.Request("DELETE", url, headers=headers)
            prepared = req.prepare()
            TbApi.pretty_print_request(prepared)

        response = requests.delete(url, headers=headers)

        # Don't fail if not found
        if(response.status_code == HTTPStatus.NOT_FOUND):
            return False

        self.validate_response(response, msg)

        return True 
開發者ID:eykamp,項目名稱:thingsboard_api_tools,代碼行數:21,代碼來源:__init__.py

示例3: do_GET

# 需要導入模塊: from http import HTTPStatus [as 別名]
# 或者: from http.HTTPStatus import NOT_FOUND [as 別名]
def do_GET(self):
        """Serve a GET request from the fixtures directory"""
        fn = p.join(p.dirname(__file__), 'fixtures', self.path[1:])
        print("path=", fn)
        try:
            with open(fn, 'rb') as f:
                stat = os.fstat(f.fileno())
                content = f.read()
        except OSError:
            self.send_error(HTTPStatus.NOT_FOUND)
        except IOError:
            self.send_error(HTTPStatus.INTERNAL_SERVER_ERROR)
        self.send_response(HTTPStatus.OK)
        self.send_header('Content-Type', self.guess_type(fn))
        self.send_header('Content-Length', stat.st_size)
        self.send_header('ETag', hashlib.sha1(content).hexdigest())
        self.end_headers()
        self.wfile.write(content) 
開發者ID:flyingcircusio,項目名稱:vulnix,代碼行數:20,代碼來源:conftest.py

示例4: test_not_found

# 需要導入模塊: from http import HTTPStatus [as 別名]
# 或者: from http.HTTPStatus import NOT_FOUND [as 別名]
def test_not_found(self):
        async with rproxy(
            self,
            self.UPSTREAM_PATH,
            subdomain=self.PROXY_SUBDOMAIN,
            path=self.PROXY_PATH,
        ) as rctx, aiohttp.ClientSession() as session:
            url = "http://%s.%s:%d%s" % (
                self.PROXY_SUBDOMAIN + ".not.found",
                self.TEST_ADDRESS,
                rctx.port,
                self.PROXY_PATH,
            )
            LOGGER.debug("rproxy url: %s", url)
            async with session.get(url) as resp:
                self.assertEqual(resp.status, HTTPStatus.NOT_FOUND) 
開發者ID:intel,項目名稱:dffml,代碼行數:18,代碼來源:test_rproxy.py

示例5: mcctx_route

# 需要導入模塊: from http import HTTPStatus [as 別名]
# 或者: from http.HTTPStatus import NOT_FOUND [as 別名]
def mcctx_route(handler):
    """
    Ensure that the labeled multicomm context requested is loaded. Return the
    mcctx if it is loaded and an error otherwise.
    """

    @wraps(handler)
    async def get_mcctx(self, request):
        mcctx = request.app["multicomm_contexts"].get(
            request.match_info["label"], None
        )
        if mcctx is None:
            return web.json_response(
                MULTICOMM_NOT_LOADED, status=HTTPStatus.NOT_FOUND
            )
        return await handler(self, request, mcctx)

    return get_mcctx 
開發者ID:intel,項目名稱:dffml,代碼行數:20,代碼來源:routes.py

示例6: sctx_route

# 需要導入模塊: from http import HTTPStatus [as 別名]
# 或者: from http.HTTPStatus import NOT_FOUND [as 別名]
def sctx_route(handler):
    """
    Ensure that the labeled source context requested is loaded. Return the sctx
    if it is loaded and an error otherwise.
    """

    @wraps(handler)
    async def get_sctx(self, request):
        sctx = request.app["source_contexts"].get(
            request.match_info["label"], None
        )
        if sctx is None:
            return web.json_response(
                SOURCE_NOT_LOADED, status=HTTPStatus.NOT_FOUND
            )
        return await handler(self, request, sctx)

    return get_sctx 
開發者ID:intel,項目名稱:dffml,代碼行數:20,代碼來源:routes.py

示例7: mctx_route

# 需要導入模塊: from http import HTTPStatus [as 別名]
# 或者: from http.HTTPStatus import NOT_FOUND [as 別名]
def mctx_route(handler):
    """
    Ensure that the labeled model context requested is loaded. Return the mctx
    if it is loaded and an error otherwise.
    """

    @wraps(handler)
    async def get_mctx(self, request):
        mctx = request.app["model_contexts"].get(
            request.match_info["label"], None
        )
        if mctx is None:
            return web.json_response(
                MODEL_NOT_LOADED, status=HTTPStatus.NOT_FOUND
            )
        return await handler(self, request, mctx)

    return get_mctx 
開發者ID:intel,項目名稱:dffml,代碼行數:20,代碼來源:routes.py

示例8: context_source

# 需要導入模塊: from http import HTTPStatus [as 別名]
# 或者: from http.HTTPStatus import NOT_FOUND [as 別名]
def context_source(self, request):
        label = request.match_info["label"]
        ctx_label = request.match_info["ctx_label"]

        if not label in request.app["sources"]:
            return web.json_response(
                {"error": f"{label} source not found"},
                status=HTTPStatus.NOT_FOUND,
            )

        # Enter the source context and pass the features
        exit_stack = request.app["exit_stack"]
        source = request.app["sources"][label]
        mctx = await exit_stack.enter_async_context(source())
        request.app["source_contexts"][ctx_label] = mctx

        return web.json_response(OK) 
開發者ID:intel,項目名稱:dffml,代碼行數:19,代碼來源:routes.py

示例9: context_model

# 需要導入模塊: from http import HTTPStatus [as 別名]
# 或者: from http.HTTPStatus import NOT_FOUND [as 別名]
def context_model(self, request):
        label = request.match_info["label"]
        ctx_label = request.match_info["ctx_label"]

        if not label in request.app["models"]:
            return web.json_response(
                {"error": f"{label} model not found"},
                status=HTTPStatus.NOT_FOUND,
            )

        # Enter the model context and pass the features
        exit_stack = request.app["exit_stack"]
        model = request.app["models"][label]
        mctx = await exit_stack.enter_async_context(model())
        request.app["model_contexts"][ctx_label] = mctx

        return web.json_response(OK) 
開發者ID:intel,項目名稱:dffml,代碼行數:19,代碼來源:routes.py

示例10: get_with_kwargs

# 需要導入模塊: from http import HTTPStatus [as 別名]
# 或者: from http.HTTPStatus import NOT_FOUND [as 別名]
def get_with_kwargs(self, *, id: Optional[str] = None, **kwargs: Optional[Any]) \
            -> Iterable[Union[Mapping, int, None]]:
        if id is not None:
            get_object = getattr(self.client, f'get_{self.str_type}')
            try:
                actual_id: Union[str, int] = int(id) if id.isdigit() else id
                object = get_object(id=actual_id, **kwargs)
                if object is not None:
                    return self.schema().dump(object).data, HTTPStatus.OK
                return None, HTTPStatus.NOT_FOUND
            except ValueError as e:
                return {'message': f'exception:{e}'}, HTTPStatus.BAD_REQUEST
        else:
            get_objects = getattr(self.client, f'get_{self.str_type}s')
            objects: List[Any] = get_objects()
            return self.schema(many=True).dump(objects).data, HTTPStatus.OK 
開發者ID:lyft,項目名稱:amundsenmetadatalibrary,代碼行數:18,代碼來源:__init__.py

示例11: get

# 需要導入模塊: from http import HTTPStatus [as 別名]
# 或者: from http.HTTPStatus import NOT_FOUND [as 別名]
def get(self, table_uri: str, column_name: str) -> Union[tuple, int, None]:
        """
        Gets column descriptions in Neo4j
        """
        try:
            description = self.client.get_column_description(table_uri=table_uri,
                                                             column_name=column_name)

            return {'description': description}, HTTPStatus.OK

        except NotFoundException:
            msg = 'table_uri {} with column {} does not exist'.format(table_uri, column_name)
            return {'message': msg}, HTTPStatus.NOT_FOUND

        except Exception:
            return {'message': 'Internal server error!'}, HTTPStatus.INTERNAL_SERVER_ERROR 
開發者ID:lyft,項目名稱:amundsenmetadatalibrary,代碼行數:18,代碼來源:column.py

示例12: test_update_job_job_does_not_exist

# 需要導入模塊: from http import HTTPStatus [as 別名]
# 或者: from http.HTTPStatus import NOT_FOUND [as 別名]
def test_update_job_job_does_not_exist(self, dev_job_fixture):
        await _load_jobs_into_chronos(dev_job_fixture)
        asgard_job = ChronosScheduledJobConverter.to_asgard_model(
            ChronosJob(**dev_job_fixture)
        )

        asgard_job.id = "job-does-not-exist"
        asgard_job.remove_namespace(self.account)

        resp = await self.client.put(
            f"/jobs/{asgard_job.id}",
            headers={
                "Authorization": f"Token {USER_WITH_MULTIPLE_ACCOUNTS_AUTH_KEY}"
            },
            json=asgard_job.dict(),
        )
        self.assertEqual(HTTPStatus.NOT_FOUND, resp.status)
        self.assertEqual(
            ErrorResource(
                errors=[ErrorDetail(msg=f"Entity not found: {asgard_job.id}")]
            ).dict(),
            await resp.json(),
        ) 
開發者ID:b2wdigital,項目名稱:asgard-api,代碼行數:25,代碼來源:test_jobs.py

示例13: test_delete_job_job_exist

# 需要導入模塊: from http import HTTPStatus [as 別名]
# 或者: from http.HTTPStatus import NOT_FOUND [as 別名]
def test_delete_job_job_exist(self, dev_job_fixture):
        await _load_jobs_into_chronos(dev_job_fixture)
        asgard_job = ChronosScheduledJobConverter.to_asgard_model(
            ChronosJob(**dev_job_fixture)
        ).remove_namespace(self.account)

        resp = await self.client.delete(
            f"/jobs/{asgard_job.id}",
            headers={
                "Authorization": f"Token {USER_WITH_MULTIPLE_ACCOUNTS_AUTH_KEY}"
            },
        )
        self.assertEqual(HTTPStatus.OK, resp.status)
        resp_data = await resp.json()
        self.assertEqual(ScheduledJobResource(job=asgard_job).dict(), resp_data)

        resp = await self.client.get(
            f"/jobs/{asgard_job.id}",
            headers={
                "Authorization": f"Token {USER_WITH_MULTIPLE_ACCOUNTS_AUTH_KEY}"
            },
        )
        self.assertEqual(HTTPStatus.NOT_FOUND, resp.status) 
開發者ID:b2wdigital,項目名稱:asgard-api,代碼行數:25,代碼來源:test_jobs.py

示例14: download_by_id

# 需要導入模塊: from http import HTTPStatus [as 別名]
# 或者: from http.HTTPStatus import NOT_FOUND [as 別名]
def download_by_id(download_id):
    file_data = cache.get(f"downloads/{download_id}")
    if not file_data:
        return Response(status=HTTPStatus.NOT_FOUND)

    file_url = file_data["file_url"]
    task_id = file_data["task_id"]
    file_path = file_data["file_path"]

    response = requests.get(file_url, stream=True)

    if response.status_code == HTTPStatus.NOT_FOUND:
        return Response(response=json.dumps({}), status=HTTPStatus.NOT_FOUND)

    filename = f"{task_id}_{file_path.strip('/')}.log"

    return Response(
        response=response.iter_content(chunk_size=4096),
        status=200,
        headers={
            "Content-Disposition": f"attachment; filename={filename}",
            "Content-Type": "application/octet-stream",
        },
    ) 
開發者ID:b2wdigital,項目名稱:asgard-api,代碼行數:26,代碼來源:tasks.py

示例15: test_exceptions_have_detail_info_about_the_request_that_failed

# 需要導入模塊: from http import HTTPStatus [as 別名]
# 或者: from http.HTTPStatus import NOT_FOUND [as 別名]
def test_exceptions_have_detail_info_about_the_request_that_failed(
        self
    ):
        """
        Cada exceção lançada deve carregar algumas infos sobre o request original.
        A ClientResponseError da aiohttp tem tudo que queremos.

        A exception lançada pelo client contém:
          - request_info original
          - status (int)
        """
        client = HttpClient()
        url = "https://httpbin.org/status/404"

        try:
            await client.get(url)
        except HTTPNotFound as e:
            self.assertEqual(HTTPStatus.NOT_FOUND, e.status)
            self.assertEqual(url, str(e.request_info.url))
            self.assertEqual("GET", e.request_info.method)
            self.assertIsNotNone(e.request_info.headers) 
開發者ID:b2wdigital,項目名稱:asgard-api,代碼行數:23,代碼來源:test_http_client.py


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