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


Python status.HTTP_400_BAD_REQUEST属性代码示例

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


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

示例1: follow_for_user

# 需要导入模块: from starlette import status [as 别名]
# 或者: from starlette.status import HTTP_400_BAD_REQUEST [as 别名]
def follow_for_user(
    profile: Profile = Depends(get_profile_by_username_from_path),
    user: User = Depends(get_current_user_authorizer()),
    profiles_repo: ProfilesRepository = Depends(get_repository(ProfilesRepository)),
) -> ProfileInResponse:
    if user.username == profile.username:
        raise HTTPException(
            status_code=HTTP_400_BAD_REQUEST, detail=strings.UNABLE_TO_FOLLOW_YOURSELF,
        )

    if profile.following:
        raise HTTPException(
            status_code=HTTP_400_BAD_REQUEST, detail=strings.USER_IS_ALREADY_FOLLOWED,
        )

    await profiles_repo.add_user_into_followers(
        target_user=profile, requested_user=user,
    )

    return ProfileInResponse(profile=profile.copy(update={"following": True})) 
开发者ID:nsidnev,项目名称:fastapi-realworld-example-app,代码行数:22,代码来源:profiles.py

示例2: unsubscribe_from_user

# 需要导入模块: from starlette import status [as 别名]
# 或者: from starlette.status import HTTP_400_BAD_REQUEST [as 别名]
def unsubscribe_from_user(
    profile: Profile = Depends(get_profile_by_username_from_path),
    user: User = Depends(get_current_user_authorizer()),
    profiles_repo: ProfilesRepository = Depends(get_repository(ProfilesRepository)),
) -> ProfileInResponse:
    if user.username == profile.username:
        raise HTTPException(
            status_code=HTTP_400_BAD_REQUEST,
            detail=strings.UNABLE_TO_UNSUBSCRIBE_FROM_YOURSELF,
        )

    if not profile.following:
        raise HTTPException(
            status_code=HTTP_400_BAD_REQUEST, detail=strings.USER_IS_NOT_FOLLOWED,
        )

    await profiles_repo.remove_user_from_followers(
        target_user=profile, requested_user=user,
    )

    return ProfileInResponse(profile=profile.copy(update={"following": False})) 
开发者ID:nsidnev,项目名称:fastapi-realworld-example-app,代码行数:23,代码来源:profiles.py

示例3: create_new_article

# 需要导入模块: from starlette import status [as 别名]
# 或者: from starlette.status import HTTP_400_BAD_REQUEST [as 别名]
def create_new_article(
    article_create: ArticleInCreate = Body(..., embed=True, alias="article"),
    user: User = Depends(get_current_user_authorizer()),
    articles_repo: ArticlesRepository = Depends(get_repository(ArticlesRepository)),
) -> ArticleInResponse:
    slug = get_slug_for_article(article_create.title)
    if await check_article_exists(articles_repo, slug):
        raise HTTPException(
            status_code=status.HTTP_400_BAD_REQUEST,
            detail=strings.ARTICLE_ALREADY_EXISTS,
        )

    article = await articles_repo.create_article(
        slug=slug,
        title=article_create.title,
        description=article_create.description,
        body=article_create.body,
        author=user,
        tags=article_create.tags,
    )
    return ArticleInResponse(article=ArticleForResponse.from_orm(article)) 
开发者ID:nsidnev,项目名称:fastapi-realworld-example-app,代码行数:23,代码来源:articles_resource.py

示例4: mark_article_as_favorite

# 需要导入模块: from starlette import status [as 别名]
# 或者: from starlette.status import HTTP_400_BAD_REQUEST [as 别名]
def mark_article_as_favorite(
    article: Article = Depends(get_article_by_slug_from_path),
    user: User = Depends(get_current_user_authorizer()),
    articles_repo: ArticlesRepository = Depends(get_repository(ArticlesRepository)),
) -> ArticleInResponse:
    if not article.favorited:
        await articles_repo.add_article_into_favorites(article=article, user=user)

        return ArticleInResponse(
            article=ArticleForResponse.from_orm(
                article.copy(
                    update={
                        "favorited": True,
                        "favorites_count": article.favorites_count + 1,
                    },
                ),
            ),
        )

    raise HTTPException(
        status_code=status.HTTP_400_BAD_REQUEST,
        detail=strings.ARTICLE_IS_ALREADY_FAVORITED,
    ) 
开发者ID:nsidnev,项目名称:fastapi-realworld-example-app,代码行数:25,代码来源:articles_common.py

示例5: test_http_exception

# 需要导入模块: from starlette import status [as 别名]
# 或者: from starlette.status import HTTP_400_BAD_REQUEST [as 别名]
def test_http_exception():
    detail = "Random HTTP error happened."
    status_code = status.HTTP_400_BAD_REQUEST
    error_code = 999
    with pytest.raises(HTTPException) as excinfo:
        raise HTTPException(
            status_code=status_code,
            error_code=error_code,
            detail=detail,
            fields=[{"field": "because of this."}],
        )

    exc = excinfo.value
    assert exc.error_code == error_code
    assert exc.detail == detail
    assert exc.status_code == status_code
    assert exc.fields == [{"field": "because of this."}] 
开发者ID:identixone,项目名称:fastapi_contrib,代码行数:19,代码来源:test_exceptions.py

示例6: destroy_vps_server

# 需要导入模块: from starlette import status [as 别名]
# 或者: from starlette.status import HTTP_400_BAD_REQUEST [as 别名]
def destroy_vps_server(db: Session = Depends(get_db), *, vps_id: int):
    # check exists of relation data
    relation_data_exists = crud_vps.check_relation_data_exists(
        db_session=db,
        id=vps_id,
        relation_key_list=['team_servers', 'redirector_c2s', 'smtp_servers']
    )
    if relation_data_exists:
        raise HTTPException(
            status_code=status.HTTP_400_BAD_REQUEST,
            detail="exists relation data",
        )

    destroy_task = celery_app.send_task(
        "destroy_vps", args=[vps_id]
    )
    with allow_join_result():
        destroy_task.get()

    destroy_result = {
        'status': crud_vps.remove(db_session=db, id=vps_id)
    }

    return dict(result=destroy_result) 
开发者ID:QAX-A-Team,项目名称:LuWu,代码行数:26,代码来源:vps.py

示例7: get_multi_runs_events

# 需要导入模块: from starlette import status [as 别名]
# 或者: from starlette.status import HTTP_400_BAD_REQUEST [as 别名]
def get_multi_runs_events(request):
    event_kind = request.path_params["event_kind"]
    force = to_bool(request.query_params.get("force"), handle_none=True)
    if event_kind not in V1ArtifactKind.allowable_values:
        raise HTTPException(
            detail="received an unrecognisable event {}.".format(event_kind),
            status_code=status.HTTP_400_BAD_REQUEST,
        )
    run_uuids = request.query_params["runs"]
    event_names = request.query_params["names"]
    orient = request.query_params.get("orient")
    orient = orient or V1Events.ORIENT_DICT
    event_names = {e for e in event_names.split(",") if e} if event_names else set([])
    run_uuids = {e for e in run_uuids.split(",") if e} if run_uuids else set([])
    events = await get_archived_operations_events(
        run_uuids=run_uuids,
        event_kind=event_kind,
        event_names=event_names,
        orient=orient,
        check_cache=not force,
    )
    return UJSONResponse({"data": events}) 
开发者ID:polyaxon,项目名称:polyaxon,代码行数:24,代码来源:endpoints.py

示例8: get_run_events

# 需要导入模块: from starlette import status [as 别名]
# 或者: from starlette.status import HTTP_400_BAD_REQUEST [as 别名]
def get_run_events(request):
    run_uuid = request.path_params["run_uuid"]
    event_kind = request.path_params["event_kind"]
    force = to_bool(request.query_params.get("force"), handle_none=True)
    if event_kind not in V1ArtifactKind.allowable_values:
        raise HTTPException(
            detail="received an unrecognisable event {}.".format(event_kind),
            status_code=status.HTTP_400_BAD_REQUEST,
        )
    event_names = request.query_params["names"]
    orient = request.query_params.get("orient")
    orient = orient or V1Events.ORIENT_DICT
    event_names = {e for e in event_names.split(",") if e} if event_names else set([])
    events = await get_archived_operation_events(
        run_uuid=run_uuid,
        event_kind=event_kind,
        event_names=event_names,
        orient=orient,
        check_cache=not force,
    )
    return UJSONResponse({"data": events}) 
开发者ID:polyaxon,项目名称:polyaxon,代码行数:23,代码来源:endpoints.py

示例9: process_operation_event

# 需要导入模块: from starlette import status [as 别名]
# 或者: from starlette.status import HTTP_400_BAD_REQUEST [as 别名]
def process_operation_event(
    events_path: str,
    event_kind: str,
    event_name: str,
    orient: str = V1Events.ORIENT_CSV,
) -> Optional[Dict]:
    if not events_path or not os.path.exists(events_path):
        return None

    async with aiofiles.open(events_path, mode="r") as f:
        contents = await f.read()
        if contents:
            if orient == V1Events.ORIENT_CSV:
                return {"name": event_name, "kind": event_kind, "data": contents}
            if orient == V1Events.ORIENT_DICT:
                df = V1Events.read(
                    kind=event_kind, name=event_name, data=contents, parse_dates=False
                )
                return {"name": event_name, "kind": event_kind, "data": df.to_dict()}
            else:
                raise HTTPException(
                    detail="received an unrecognisable orient value {}.".format(orient),
                    status_code=status.HTTP_400_BAD_REQUEST,
                )
    return None 
开发者ID:polyaxon,项目名称:polyaxon,代码行数:27,代码来源:events.py

示例10: update_current_user

# 需要导入模块: from starlette import status [as 别名]
# 或者: from starlette.status import HTTP_400_BAD_REQUEST [as 别名]
def update_current_user(
    user_update: UserInUpdate = Body(..., embed=True, alias="user"),
    current_user: User = Depends(get_current_user_authorizer()),
    users_repo: UsersRepository = Depends(get_repository(UsersRepository)),
) -> UserInResponse:
    if user_update.username and user_update.username != current_user.username:
        if await check_username_is_taken(users_repo, user_update.username):
            raise HTTPException(
                status_code=HTTP_400_BAD_REQUEST, detail=strings.USERNAME_TAKEN,
            )

    if user_update.email and user_update.email != current_user.email:
        if await check_email_is_taken(users_repo, user_update.email):
            raise HTTPException(
                status_code=HTTP_400_BAD_REQUEST, detail=strings.EMAIL_TAKEN,
            )

    user = await users_repo.update_user(user=current_user, **user_update.dict())

    token = jwt.create_access_token_for_user(user, str(config.SECRET_KEY))
    return UserInResponse(
        user=UserWithToken(
            username=user.username,
            email=user.email,
            bio=user.bio,
            image=user.image,
            token=token,
        ),
    ) 
开发者ID:nsidnev,项目名称:fastapi-realworld-example-app,代码行数:31,代码来源:users.py

示例11: login

# 需要导入模块: from starlette import status [as 别名]
# 或者: from starlette.status import HTTP_400_BAD_REQUEST [as 别名]
def login(
    user_login: UserInLogin = Body(..., embed=True, alias="user"),
    users_repo: UsersRepository = Depends(get_repository(UsersRepository)),
) -> UserInResponse:
    wrong_login_error = HTTPException(
        status_code=HTTP_400_BAD_REQUEST, detail=strings.INCORRECT_LOGIN_INPUT,
    )

    try:
        user = await users_repo.get_user_by_email(email=user_login.email)
    except EntityDoesNotExist as existence_error:
        raise wrong_login_error from existence_error

    if not user.check_password(user_login.password):
        raise wrong_login_error

    token = jwt.create_access_token_for_user(user, str(config.SECRET_KEY))
    return UserInResponse(
        user=UserWithToken(
            username=user.username,
            email=user.email,
            bio=user.bio,
            image=user.image,
            token=token,
        ),
    ) 
开发者ID:nsidnev,项目名称:fastapi-realworld-example-app,代码行数:28,代码来源:authentication.py

示例12: register

# 需要导入模块: from starlette import status [as 别名]
# 或者: from starlette.status import HTTP_400_BAD_REQUEST [as 别名]
def register(
    user_create: UserInCreate = Body(..., embed=True, alias="user"),
    users_repo: UsersRepository = Depends(get_repository(UsersRepository)),
) -> UserInResponse:
    if await check_username_is_taken(users_repo, user_create.username):
        raise HTTPException(
            status_code=HTTP_400_BAD_REQUEST, detail=strings.USERNAME_TAKEN,
        )

    if await check_email_is_taken(users_repo, user_create.email):
        raise HTTPException(
            status_code=HTTP_400_BAD_REQUEST, detail=strings.EMAIL_TAKEN,
        )

    user = await users_repo.create_user(**user_create.dict())

    token = jwt.create_access_token_for_user(user, str(config.SECRET_KEY))
    return UserInResponse(
        user=UserWithToken(
            username=user.username,
            email=user.email,
            bio=user.bio,
            image=user.image,
            token=token,
        ),
    ) 
开发者ID:nsidnev,项目名称:fastapi-realworld-example-app,代码行数:28,代码来源:authentication.py

示例13: http_exception_handler

# 需要导入模块: from starlette import status [as 别名]
# 或者: from starlette.status import HTTP_400_BAD_REQUEST [as 别名]
def http_exception_handler(request: Request, exc: HTTPException):
    failed_res = BaseFailedResponseModel(errors=[exc.detail]).dict()
    status_code = exc.status_code or status.HTTP_400_BAD_REQUEST
    return JSONResponse(failed_res, status_code=status_code) 
开发者ID:QAX-A-Team,项目名称:LuWu,代码行数:6,代码来源:main.py

示例14: post

# 需要导入模块: from starlette import status [as 别名]
# 或者: from starlette.status import HTTP_400_BAD_REQUEST [as 别名]
def post(self, request):
        content_type = request.headers.get("Content-Type", "")

        if "application/json" in content_type:
            data = await request.json()
        elif "application/graphql" in content_type:
            body = await request.body()
            text = body.decode()
            data = {"query": text}
        elif "query" in request.query_params:
            data = request.query_params
        else:
            return PlainTextResponse(
                "Unsupported Media Type",
                status_code=status.HTTP_415_UNSUPPORTED_MEDIA_TYPE,
            )

        try:
            query = data["query"]
            variables = data.get("variables")
        except KeyError:
            return PlainTextResponse(
                "No GraphQL query found in the request",
                status_code=status.HTTP_400_BAD_REQUEST,
            )

        result = await self.execute(
            query, variables=variables, request=request
        )
        status_code = status.HTTP_200_OK
        return Response(
            json.dumps(result, cls=GraphQLEncoder),
            status_code=status_code,
            media_type='application/json'
        ) 
开发者ID:ethe,项目名称:pygraphy,代码行数:37,代码来源:view.py

示例15: upload_logs

# 需要导入模块: from starlette import status [as 别名]
# 或者: from starlette.status import HTTP_400_BAD_REQUEST [as 别名]
def upload_logs(run_uuid: str, logs: List[V1Log]):
    if not settings.AGENT_CONFIG.artifacts_store:
        raise HTTPException(
            detail="Run's logs was not collected, resource was not found.",
            status_code=status.HTTP_400_BAD_REQUEST,
        )
    for c_logs in V1Logs.chunk_logs(logs):
        last_file = datetime.timestamp(c_logs.logs[-1].timestamp)
        subpath = "{}/plxlogs/{}".format(run_uuid, last_file)
        await upload_data(subpath=subpath, data=c_logs.to_dict(dump=True)) 
开发者ID:polyaxon,项目名称:polyaxon,代码行数:12,代码来源:logs.py


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