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


Python web.Request方法代码示例

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


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

示例1: messages

# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import Request [as 别名]
def messages(req: Request) -> Response:
    # Main bot message handler.
    if "application/json" in req.headers["Content-Type"]:
        body = await req.json()
    else:
        return Response(status=415)

    inbound_activity: Activity = Activity().deserialize(body)

    current_conversation_id = inbound_activity.conversation.id
    current_service_url = inbound_activity.service_url

    next_conversation_id = FACTORY.create_skill_conversation_id(current_conversation_id, current_service_url)

    await CLIENT.post_activity(CONFIG.APP_ID, CONFIG.SKILL_APP_ID, TO_URI, SERVICE_URL, next_conversation_id, inbound_activity)
    return Response(status=201) 
开发者ID:microsoft,项目名称:botbuilder-python,代码行数:18,代码来源:app.py

示例2: messages

# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import Request [as 别名]
def messages(req: Request) -> Response:
    # Main bot message handler.
    if "application/json" in req.headers["Content-Type"]:
        body = await req.json()
    else:
        return Response(status=415)

    activity = Activity().deserialize(body)
    auth_header = req.headers["Authorization"] if "Authorization" in req.headers else ""

    try:
        response = await ADAPTER.process_activity(activity, auth_header, BOT.on_turn)
        if response:
            return json_response(data=response.body, status=response.status)
        return Response(status=201)
    except Exception as exception:
        raise exception 
开发者ID:microsoft,项目名称:botbuilder-python,代码行数:19,代码来源:app.py

示例3: messages

# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import Request [as 别名]
def messages(req: Request) -> Response:
    # Main bot message handler.
    if "application/json" in req.headers["Content-Type"]:
        body = await req.json()
    else:
        return Response(status=415)

    activity = Activity().deserialize(body)
    auth_header = req.headers["Authorization"] if "Authorization" in req.headers else ""

    try:
        invoke_response = await ADAPTER.process_activity(
            activity, auth_header, BOT.on_turn
        )
        if invoke_response:
            return json_response(
                data=invoke_response.body, status=invoke_response.status
            )
        return Response(status=201)
    except PermissionError:
        return Response(status=401)
    except Exception:
        return Response(status=500) 
开发者ID:microsoft,项目名称:botbuilder-python,代码行数:25,代码来源:app.py

示例4: messages

# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import Request [as 别名]
def messages(req: Request) -> Response:
    # Create the Bot
    bot = AuthBot(CONVERSATION_STATE, USER_STATE, DIALOG)

    # Main bot message handler.
    if "application/json" in req.headers["Content-Type"]:
        body = await req.json()
    else:
        return Response(status=415)

    activity = Activity().deserialize(body)
    auth_header = req.headers["Authorization"] if "Authorization" in req.headers else ""

    try:
        await ADAPTER.process_activity(activity, auth_header, bot.on_turn)
        return Response(status=201)
    except Exception as exception:
        raise exception 
开发者ID:microsoft,项目名称:botbuilder-python,代码行数:20,代码来源:app.py

示例5: read_client_auth_request

# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import Request [as 别名]
def read_client_auth_request(request: web.Request) -> Tuple[Optional[AuthRequestInfo],
                                                                  Optional[web.Response]]:
    server_name = request.match_info.get("server", None)
    server = registration_secrets().get(server_name, None)
    if not server:
        return None, resp.server_not_found
    try:
        body = await request.json()
    except JSONDecodeError:
        return None, resp.body_not_json
    try:
        username = body["username"]
        password = body["password"]
    except KeyError:
        return None, resp.username_or_password_missing
    try:
        base_url = server["url"]
        secret = server["secret"]
    except KeyError:
        return None, resp.invalid_server
    api = HTTPAPI(base_url, "", loop=get_loop())
    user_type = body.get("user_type", "bot")
    return AuthRequestInfo(api, secret, username, password, user_type), None 
开发者ID:maubot,项目名称:maubot,代码行数:25,代码来源:client_auth.py

示例6: register

# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import Request [as 别名]
def register(request: web.Request) -> web.Response:
    info, err = await read_client_auth_request(request)
    if err is not None:
        return err
    api, secret, username, password, user_type = info
    res = await api.request(Method.GET, Path.admin.register)
    nonce = res["nonce"]
    mac = generate_mac(secret, nonce, username, password, user_type=user_type)
    try:
        return web.json_response(await api.request(Method.POST, Path.admin.register, content={
            "nonce": nonce,
            "username": username,
            "password": password,
            "admin": False,
            "mac": mac,
            # Older versions of synapse will ignore this field if it is None
            "user_type": user_type,
        }))
    except MatrixRequestError as e:
        return web.json_response({
            "errcode": e.errcode,
            "error": e.message,
            "http_status": e.http_status,
        }, status=HTTPStatus.INTERNAL_SERVER_ERROR) 
开发者ID:maubot,项目名称:maubot,代码行数:26,代码来源:client_auth.py

示例7: login

# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import Request [as 别名]
def login(request: web.Request) -> web.Response:
    info, err = await read_client_auth_request(request)
    if err is not None:
        return err
    api, _, username, password, _ = info
    device_id = ''.join(random.choices(string.ascii_uppercase + string.digits, k=8))
    try:
        return web.json_response(await api.request(Method.POST, Path.login, content={
            "type": "m.login.password",
            "identifier": {
                "type": "m.id.user",
                "user": username,
            },
            "password": password,
            "device_id": f"maubot_{device_id}",
        }))
    except MatrixRequestError as e:
        return web.json_response({
            "errcode": e.errcode,
            "error": e.message,
        }, status=e.http_status) 
开发者ID:maubot,项目名称:maubot,代码行数:23,代码来源:client_auth.py

示例8: deserialize_from_body

# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import Request [as 别名]
def deserialize_from_body(
    request: Request, target_model: Type[Model]
) -> Activity:
    if "application/json" in request.headers["Content-Type"]:
        body = await request.json()
    else:
        return Response(status=415)

    return target_model().deserialize(body) 
开发者ID:microsoft,项目名称:botbuilder-python,代码行数:11,代码来源:aiohttp_channel_service.py

示例9: messages

# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import Request [as 别名]
def messages(req: Request) -> Response:
    # Main bot message handler.
    if "application/json" in req.headers["Content-Type"]:
        body = await req.json()
    else:
        return Response(status=415)

    activity = Activity().deserialize(body)
    auth_header = req.headers["Authorization"] if "Authorization" in req.headers else ""

    try:
        await ADAPTER.process_activity(activity, auth_header, BOT.on_turn)
        return Response(status=201)
    except Exception as exception:
        raise exception 
开发者ID:microsoft,项目名称:botbuilder-python,代码行数:17,代码来源:app.py

示例10: example

# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import Request [as 别名]
def example(self, request: web.Request) -> str:
        await asyncio.sleep(1)
        return '友達'  # tomodachi 
开发者ID:kalaspuff,项目名称:tomodachi,代码行数:5,代码来源:http_simple_service.py

示例11: example_with_id

# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import Request [as 别名]
def example_with_id(self, request: web.Request, id: str) -> str:
        return '友達 (id: {})'.format(id) 
开发者ID:kalaspuff,项目名称:tomodachi,代码行数:4,代码来源:http_simple_service.py

示例12: response_object

# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import Request [as 别名]
def response_object(self, request: web.Request) -> HttpResponse:
        return HttpResponse(body='{"data": true}', status=200, content_type='application/json') 
开发者ID:kalaspuff,项目名称:tomodachi,代码行数:4,代码来源:http_simple_service.py

示例13: error_404

# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import Request [as 别名]
def error_404(self, request: web.Request) -> str:
        return 'error 404' 
开发者ID:kalaspuff,项目名称:tomodachi,代码行数:4,代码来源:http_simple_service.py

示例14: middleware_function

# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import Request [as 别名]
def middleware_function(func: Callable, service: Any, request: web.Request, context: Dict, *args: Any, **kwargs: Any) -> Any:
    # Functionality before function is called
    service.log('middleware before')

    return_value = await func(*args, **kwargs)

    # There's also the possibility to pass in extra arguments or keywords arguments, for example:
    # return_value = await func(*args, id='overridden', **kwargs)

    # Functinoality after function is called
    service.log('middleware after')

    return return_value 
开发者ID:kalaspuff,项目名称:tomodachi,代码行数:15,代码来源:http_middleware_service.py

示例15: example_with_id

# 需要导入模块: from aiohttp import web [as 别名]
# 或者: from aiohttp.web import Request [as 别名]
def example_with_id(self, request: web.Request, id: str, **kwargs: Any) -> str:
        return '友達 (id: {})'.format(id) 
开发者ID:kalaspuff,项目名称:tomodachi,代码行数:4,代码来源:http_middleware_service.py


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