跳转至

request

feishu.utils.request

request

Python
request(method: str | Callable, dest: str, data: Dict | None = None, params: Dict | None = None, headers: Dict | None = None, timeout: int = 120, token: str | None = None, app_id: str | None = None, app_secret: str | None = None, retry_codes: tuple[int, ...] = (500, 502, 503, 504), **kwargs) -> NestedDict

向指定目的地发送请求。

Parameters:

Name Type Description Default

method

str | Callable

请求方法。可以是字符串(’GET’、’POST’、’PUT’、’PATCH’、’DELETE’)或者函数。

required

dest

str

目的地统一资源定位符。这个地址应该是相对于飞书 API 的。

required

data

Dict | None

请求数据。默认为 None

None

params

Dict | None

请求参数。默认为 None

None

headers

Dict | None

请求头。默认为 {}

None

timeout

int

超时时间。默认为 120 秒。

120

token

str | None

访问凭证。如果为 None,则会自动获取。 如果 token 为 None,则 app_id 和 app_secret 必须不为 None

None

app_id

str | None

应用唯一标识(以cli_开头)。默认为 None

None

app_secret

str | None

应用秘钥。默认为 None

None

retry_codes

tuple[int, ...]

需要重试的状态码。默认为 (500, 502, 503, 504)

(500, 502, 503, 504)

kwargs

其他参数。

{}

Returns:

Type Description
NestedDict

请求结果

Raises:

Type Description
ValueError

如果 token, app_id, 和 app_secret 都为 None

FeishuException

飞书 API 返回的错误。

Source code in feishu/utils/request.py
Python
@retry(
    stop=stop_after_attempt(variables.MAX_RETRIES),
    wait=wait_random_exponential(exp_base=variables.BACKOFF_BASE),
    retry=retry_if_exception_type((httpx.RequestError, FeishuException)),
)
@authorize
def request(
    method: str | Callable,
    dest: str,
    data: Dict | None = None,
    params: Dict | None = None,
    headers: Dict | None = None,
    timeout: int = 120,
    token: str | None = None,
    app_id: str | None = None,
    app_secret: str | None = None,
    retry_codes: tuple[int, ...] = (500, 502, 503, 504),
    **kwargs,
) -> NestedDict:
    r"""
    向指定目的地发送请求。

    Args:
        method: 请求方法。可以是字符串('GET'、'POST'、'PUT'、'PATCH'、'DELETE')或者函数。
        dest: 目的地统一资源定位符。这个地址应该是相对于飞书 API 的。
        data: 请求数据。默认为 `None`。
        params: 请求参数。默认为 `None`。
        headers: 请求头。默认为 `{}`。
        timeout: 超时时间。默认为 120 秒。
        token: 访问凭证。如果为 `None`,则会自动获取。
            如果 token 为 `None`,则 app_id 和 app_secret 必须不为 `None`。
        app_id: 应用唯一标识(以`cli_`开头)。默认为 `None`。
        app_secret: 应用秘钥。默认为 `None`。
        retry_codes: 需要重试的状态码。默认为 `(500, 502, 503, 504)`
        kwargs: 其他参数。

    Returns:
        请求结果

    Raises:
        ValueError: 如果 token, app_id, 和 app_secret 都为 `None`。
        FeishuException: 飞书 API 返回的错误。
    """
    if dest.startswith("/"):
        dest = dest[1:]
    url = f"{variables.BASE_URL}{dest}"
    headers = headers or {}

    if token is None:
        if app_id is None or app_secret is None:
            raise ValueError("token, app_id, and app_secret cannot all be None.")
        token = get_tenant_access_token(app_id, app_secret, timeout)
    headers["Authorization"] = f"Bearer {token}"

    if data is not None:
        headers["Content-Type"] = "application/json"

    if callable(method):
        response = method(url, headers=headers, json=data, params=params, timeout=timeout, **kwargs)
    else:
        response = httpx.request(method, url, headers=headers, json=data, params=params, timeout=timeout, **kwargs)

    ret = response.json()
    if ret.get("code") == 0:
        return NestedDict(ret)

    if response.status_code in retry_codes:
        raise FeishuServerError(ret.get("code"), ret.get("msg"))

    raise FeishuException(ret.get("code"), f"Request failed with status code: {response.status_code}")

post

Python
post(dest: str, data: Dict | None = None, params: Dict | None = None, headers: Dict | None = None, timeout: int = 120, token: str | None = None, app_id: str | None = None, app_secret: str | None = None, **kwargs) -> NestedDict

向指定目的地发送 POST 请求。

Parameters:

Name Type Description Default

dest

str

目的地统一资源定位符。这个地址应该是相对于飞书 API 的。

required

headers

Dict | None

请求头。默认为 {}

None

params

Dict | None

请求参数。默认为 {}

None

timeout

int

超时时间。默认为 120 秒。

120

token

str | None

访问凭证。如果为 None,则会自动获取。 如果 token 为 None,则 app_id 和 app_secret 必须不为 None

None

app_id

str | None

应用唯一标识(以cli_开头)。默认为 None

None

app_secret

str | None

应用秘钥。默认为 None

None

Returns:

Type Description
NestedDict

请求结果

Raises:

Type Description
ValueError

如果 token, app_id, 和 app_secret 都为 None

Examples:

Python Console Session
>>> data = {
...     "receive_id_type": "open_id",
...     "receive_id": "ou_7d8a6e6df7621556ce0d21922b676706ccs",
...     "msg_type": "text",
...     "content": "{\"text\":\"test content\"}",
...     "uuid": "a0d69e20-1dd1-458b-k525-dfeca4015204"
... }
>>> post(
...     'im/v1/messages',
...     data=data,
...     app_id='cli_slkdjalasdkjasd',
...     app_secret='dskLLdkasdjlasdKK'
... )
NestedDict(
  ('code'): 0
  ('msg'): 'success'
  ('data'): NestedDict(
    ('message_id'): 'om_dc13264520392913993dd051dba21dcf'
    ('root_id'): 'om_40eb06e7b84dc71c03e009ad3c754195'
    ('parent_id'): 'om_d4be107c616aed9c1da8ed8068570a9f'
    ('thread_id'): 'omt_d4be107c616a'
    ('msg_type'): 'card'
    ('create_time'): '1635675360'
    ('update_time'): '1635675360'
    ('deleted'): False
    ('updated'): False
    ('chat_id'): 'oc_5ad11d72b830411d72b836c20'
    ('sender'): NestedDict(
      ('id'): 'cli_9f427eec54ae901b'
      ('id_type'): 'app_id'
      ('sender_type'): 'app'
      ('tenant_key'): '736588c9260f175e'
    )
    ('body'): NestedDict(
      ('content'): '{"text":"@_user_1 test content"}'
    )
    ('mentions'): [NestedDict(
      ('key'): '@_user_1'
      ('id'): 'ou_155184d1e73cbfb8973e5a9e698e74f2'
      ('id_type'): 'open_id'
      ('name'): 'Chang'
      ('tenant_key'): '736588c9260f175e'
    )]
    ('upper_message_id'): 'om_40eb06e7b84dc71c03e009ad3c754195'
  )
)
Source code in feishu/utils/request.py
Python
def post(
    dest: str,
    data: Dict | None = None,
    params: Dict | None = None,
    headers: Dict | None = None,
    timeout: int = 120,
    token: str | None = None,
    app_id: str | None = None,
    app_secret: str | None = None,
    **kwargs,
) -> NestedDict:
    r"""
    向指定目的地发送 POST 请求。

    Args:
        dest: 目的地统一资源定位符。这个地址应该是相对于飞书 API 的。
        headers: 请求头。默认为 `{}`。
        params: 请求参数。默认为 `{}`。
        timeout: 超时时间。默认为 120 秒。
        token: 访问凭证。如果为 `None`,则会自动获取。
            如果 token 为 `None`,则 app_id 和 app_secret 必须不为 `None`。
        app_id: 应用唯一标识(以`cli_`开头)。默认为 `None`。
        app_secret: 应用秘钥。默认为 `None`。

    Returns:
        请求结果

    Raises:
        ValueError: 如果 token, app_id, 和 app_secret 都为 `None`。

    Examples:
        >>> data = {
        ...     "receive_id_type": "open_id",
        ...     "receive_id": "ou_7d8a6e6df7621556ce0d21922b676706ccs",
        ...     "msg_type": "text",
        ...     "content": "{\"text\":\"test content\"}",
        ...     "uuid": "a0d69e20-1dd1-458b-k525-dfeca4015204"
        ... }
        >>> post(
        ...     'im/v1/messages',
        ...     data=data,
        ...     app_id='cli_slkdjalasdkjasd',
        ...     app_secret='dskLLdkasdjlasdKK'
        ... )  # doctest:+SKIP
        NestedDict(
          ('code'): 0
          ('msg'): 'success'
          ('data'): NestedDict(
            ('message_id'): 'om_dc13264520392913993dd051dba21dcf'
            ('root_id'): 'om_40eb06e7b84dc71c03e009ad3c754195'
            ('parent_id'): 'om_d4be107c616aed9c1da8ed8068570a9f'
            ('thread_id'): 'omt_d4be107c616a'
            ('msg_type'): 'card'
            ('create_time'): '1635675360'
            ('update_time'): '1635675360'
            ('deleted'): False
            ('updated'): False
            ('chat_id'): 'oc_5ad11d72b830411d72b836c20'
            ('sender'): NestedDict(
              ('id'): 'cli_9f427eec54ae901b'
              ('id_type'): 'app_id'
              ('sender_type'): 'app'
              ('tenant_key'): '736588c9260f175e'
            )
            ('body'): NestedDict(
              ('content'): '{"text":"@_user_1 test content"}'
            )
            ('mentions'): [NestedDict(
              ('key'): '@_user_1'
              ('id'): 'ou_155184d1e73cbfb8973e5a9e698e74f2'
              ('id_type'): 'open_id'
              ('name'): 'Chang'
              ('tenant_key'): '736588c9260f175e'
            )]
            ('upper_message_id'): 'om_40eb06e7b84dc71c03e009ad3c754195'
          )
        )
    """
    return request(
        "POST",
        dest,
        data=data,
        params=params,
        headers=headers,
        timeout=timeout,
        token=token,
        app_id=app_id,
        app_secret=app_secret,
        **kwargs,
    )

get

Python
get(dest: str, params: Dict | None = None, headers: Dict | None = None, timeout: int = 120, token: str | None = None, app_id: str | None = None, app_secret: str | None = None, **kwargs) -> NestedDict

向指定目的地发送 GET 请求。

Parameters:

Name Type Description Default

dest

str

目的地统一资源定位符。这个地址应该是相对于飞书 API 的。

required

headers

Dict | None

请求头。默认为 {}

None

params

Dict | None

请求参数。默认为 {}

None

timeout

int

超时时间。默认为 120 秒。

120

token

str | None

访问凭证。如果为 None,则会自动获取。 如果 token 为 None,则 app_id 和 app_secret 必须不为 None

None

app_id

str | None

应用唯一标识(以cli_开头)。默认为 None

None

app_secret

str | None

应用秘钥。默认为 None

None

Returns:

Type Description
NestedDict

请求结果

Raises:

Type Description
ValueError

如果 token, app_id, 和 app_secret 都为 None

Examples:

Python Console Session
>>> get(
...     'im/v1/messages/:message_id',
...     app_id='cli_slkdjalasdkjasd',
...     app_secret='dskLLdkasdjlasdKK'
... )
NestedDict(
  ('code'): 0
  ('msg'): 'success'
  ('data'): NestedDict(
    ('items'): [NestedDict(
      ('message_id'): 'om_dc13264520392913993dd051dba21dcf'
      ('root_id'): 'om_40eb06e7b84dc71c03e009ad3c754195'
      ('parent_id'): 'om_d4be107c616aed9c1da8ed8068570a9f'
      ('thread_id'): 'omt_d4be107c616a'
      ('msg_type'): 'card'
      ('create_time'): '1635675360'
      ('update_time'): '1635675360'
      ('deleted'): False
      ('updated'): False
      ('chat_id'): 'oc_5ad11d72b830411d72b836c20'
      ('sender'): NestedDict(
        ('id'): 'cli_9f427eec54ae901b'
        ('id_type'): 'app_id'
        ('sender_type'): 'app'
        ('tenant_key'): '736588c9260f175e'
      )
      ('body'): NestedDict(
        ('content'): '{"text":"@_user_1 test content"}'
      )
      ('mentions'): [NestedDict(
        ('key'): '@_user_1'
        ('id'): 'ou_155184d1e73cbfb8973e5a9e698e74f2'
        ('id_type'): 'open_id'
        ('name'): 'Chang'
        ('tenant_key'): '736588c9260f175e'
      )]
    ('upper_message_id'): 'om_40eb06e7b84dc71c03e009ad3c754195'
    )]
  )
)
Source code in feishu/utils/request.py
Python
def get(
    dest: str,
    params: Dict | None = None,
    headers: Dict | None = None,
    timeout: int = 120,
    token: str | None = None,
    app_id: str | None = None,
    app_secret: str | None = None,
    **kwargs,
) -> NestedDict:
    r"""
    向指定目的地发送 GET 请求。

    Args:
        dest: 目的地统一资源定位符。这个地址应该是相对于飞书 API 的。
        headers: 请求头。默认为 `{}`。
        params: 请求参数。默认为 `{}`。
        timeout: 超时时间。默认为 120 秒。
        token: 访问凭证。如果为 `None`,则会自动获取。
            如果 token 为 `None`,则 app_id 和 app_secret 必须不为 `None`。
        app_id: 应用唯一标识(以`cli_`开头)。默认为 `None`。
        app_secret: 应用秘钥。默认为 `None`。

    Returns:
        请求结果

    Raises:
        ValueError: 如果 token, app_id, 和 app_secret 都为 `None`。

    Examples:
        >>> get(
        ...     'im/v1/messages/:message_id',
        ...     app_id='cli_slkdjalasdkjasd',
        ...     app_secret='dskLLdkasdjlasdKK'
        ... )  # doctest:+SKIP
        NestedDict(
          ('code'): 0
          ('msg'): 'success'
          ('data'): NestedDict(
            ('items'): [NestedDict(
              ('message_id'): 'om_dc13264520392913993dd051dba21dcf'
              ('root_id'): 'om_40eb06e7b84dc71c03e009ad3c754195'
              ('parent_id'): 'om_d4be107c616aed9c1da8ed8068570a9f'
              ('thread_id'): 'omt_d4be107c616a'
              ('msg_type'): 'card'
              ('create_time'): '1635675360'
              ('update_time'): '1635675360'
              ('deleted'): False
              ('updated'): False
              ('chat_id'): 'oc_5ad11d72b830411d72b836c20'
              ('sender'): NestedDict(
                ('id'): 'cli_9f427eec54ae901b'
                ('id_type'): 'app_id'
                ('sender_type'): 'app'
                ('tenant_key'): '736588c9260f175e'
              )
              ('body'): NestedDict(
                ('content'): '{"text":"@_user_1 test content"}'
              )
              ('mentions'): [NestedDict(
                ('key'): '@_user_1'
                ('id'): 'ou_155184d1e73cbfb8973e5a9e698e74f2'
                ('id_type'): 'open_id'
                ('name'): 'Chang'
                ('tenant_key'): '736588c9260f175e'
              )]
            ('upper_message_id'): 'om_40eb06e7b84dc71c03e009ad3c754195'
            )]
          )
        )
    """
    return request(
        "GET",
        dest,
        headers=headers,
        params=params,
        timeout=timeout,
        token=token,
        app_id=app_id,
        app_secret=app_secret,
        **kwargs,
    )

put

Python
put(dest: str, data: Dict | None = None, params: Dict | None = None, headers: Dict | None = None, timeout: int = 120, token: str | None = None, app_id: str | None = None, app_secret: str | None = None, **kwargs) -> NestedDict

向指定目的地发送 PUT 请求。

Parameters:

Name Type Description Default

dest

str

目的地统一资源定位符。这个地址应该是相对于飞书 API 的。

required

headers

Dict | None

请求头。默认为 {}

None

params

Dict | None

请求参数。默认为 {}

None

timeout

int

超时时间。默认为 120 秒。

120

token

str | None

访问凭证。如果为 None,则会自动获取。 如果 token 为 None,则 app_id 和 app_secret 必须不为 None

None

app_id

str | None

应用唯一标识(以cli_开头)。默认为 None

None

app_secret

str | None

应用秘钥。默认为 None

None

Returns:

Type Description
NestedDict

请求结果

Raises:

Type Description
ValueError

如果 token, app_id, 和 app_secret 都为 None

Examples:

Python Console Session
>>> data = {"msg_type": "text", "content": "{\"text\":\"test content\"}"}
>>> put(
...     'im/v1/messages/:message_id',
...     data=data,
...     app_id='cli_slkdjalasdkjasd',
...     app_secret='dskLLdkasdjlasdKK'
... )
NestedDict(
  ('code'): 0
  ('msg'): 'success'
  ('data'): NestedDict(
    ('message_id'): 'om_dc13264520392913993dd051dba21dcf'
    ('root_id'): 'om_40eb06e7b84dc71c03e009ad3c754195'
    ('parent_id'): 'om_d4be107c616aed9c1da8ed8068570a9f'
    ('thread_id'): 'omt_d4be107c616a'
    ('msg_type'): 'card'
    ('create_time'): '1635675360'
    ('update_time'): '1635675420'
    ('deleted'): False
    ('updated'): True
    ('chat_id'): 'oc_5ad11d72b830411d72b836c20'
    ('sender'): NestedDict(
      ('id'): 'cli_9f427eec54ae901b'
      ('id_type'): 'app_id'
      ('sender_type'): 'app'
      ('tenant_key'): '736588c9260f175e'
    )
    ('body'): NestedDict(
      ('content'): '{"text":"@_user_1 test content"}'
    )
    ('mentions'): [NestedDict(
      ('key'): '@_user_1'
      ('id'): 'ou_155184d1e73cbfb8973e5a9e698e74f2'
      ('id_type'): 'open_id'
      ('name'): 'Chang'
      ('tenant_key'): '736588c9260f175e'
    )]
    ('upper_message_id'): 'om_40eb06e7b84dc71c03e00ida3c754892'
  )
)
Source code in feishu/utils/request.py
Python
def put(
    dest: str,
    data: Dict | None = None,
    params: Dict | None = None,
    headers: Dict | None = None,
    timeout: int = 120,
    token: str | None = None,
    app_id: str | None = None,
    app_secret: str | None = None,
    **kwargs,
) -> NestedDict:
    r"""
    向指定目的地发送 PUT 请求。

    Args:
        dest: 目的地统一资源定位符。这个地址应该是相对于飞书 API 的。
        headers: 请求头。默认为 `{}`。
        params: 请求参数。默认为 `{}`。
        timeout: 超时时间。默认为 120 秒。
        token: 访问凭证。如果为 `None`,则会自动获取。
            如果 token 为 `None`,则 app_id 和 app_secret 必须不为 `None`。
        app_id: 应用唯一标识(以`cli_`开头)。默认为 `None`。
        app_secret: 应用秘钥。默认为 `None`。

    Returns:
        请求结果

    Raises:
        ValueError: 如果 token, app_id, 和 app_secret 都为 `None`。

    Examples:
        >>> data = {"msg_type": "text", "content": "{\"text\":\"test content\"}"}
        >>> put(
        ...     'im/v1/messages/:message_id',
        ...     data=data,
        ...     app_id='cli_slkdjalasdkjasd',
        ...     app_secret='dskLLdkasdjlasdKK'
        ... )  # doctest:+SKIP
        NestedDict(
          ('code'): 0
          ('msg'): 'success'
          ('data'): NestedDict(
            ('message_id'): 'om_dc13264520392913993dd051dba21dcf'
            ('root_id'): 'om_40eb06e7b84dc71c03e009ad3c754195'
            ('parent_id'): 'om_d4be107c616aed9c1da8ed8068570a9f'
            ('thread_id'): 'omt_d4be107c616a'
            ('msg_type'): 'card'
            ('create_time'): '1635675360'
            ('update_time'): '1635675420'
            ('deleted'): False
            ('updated'): True
            ('chat_id'): 'oc_5ad11d72b830411d72b836c20'
            ('sender'): NestedDict(
              ('id'): 'cli_9f427eec54ae901b'
              ('id_type'): 'app_id'
              ('sender_type'): 'app'
              ('tenant_key'): '736588c9260f175e'
            )
            ('body'): NestedDict(
              ('content'): '{"text":"@_user_1 test content"}'
            )
            ('mentions'): [NestedDict(
              ('key'): '@_user_1'
              ('id'): 'ou_155184d1e73cbfb8973e5a9e698e74f2'
              ('id_type'): 'open_id'
              ('name'): 'Chang'
              ('tenant_key'): '736588c9260f175e'
            )]
            ('upper_message_id'): 'om_40eb06e7b84dc71c03e00ida3c754892'
          )
        )
    """
    return request(
        "PUT",
        dest,
        data=data,
        params=params,
        headers=headers,
        timeout=timeout,
        token=token,
        app_id=app_id,
        app_secret=app_secret,
        **kwargs,
    )

patch

Python
patch(dest: str, data: Dict | None = None, params: Dict | None = None, headers: Dict | None = None, timeout: int = 120, token: str | None = None, app_id: str | None = None, app_secret: str | None = None, **kwargs) -> NestedDict

向指定目的地发送 PUT 请求。

Parameters:

Name Type Description Default

dest

str

目的地统一资源定位符。这个地址应该是相对于飞书 API 的。

required

headers

Dict | None

请求头。默认为 {}

None

params

Dict | None

请求参数。默认为 {}

None

timeout

int

超时时间。默认为 120 秒。

120

token

str | None

访问凭证。如果为 None,则会自动获取。 如果 token 为 None,则 app_id 和 app_secret 必须不为 None

None

app_id

str | None

应用唯一标识(以cli_开头)。默认为 None

None

app_secret

str | None

应用秘钥。默认为 None

None

Returns:

Type Description
NestedDict

请求结果

Raises:

Type Description
ValueError

如果 token, app_id, 和 app_secret 都为 None

Examples:

Python Console Session
>>> data = {"content": "{\"text\":\"test content\"}"}
>>> patch(
...     'im/v1/messages/:message_id',
...     data=data,
...     app_id='cli_slkdjalasdkjasd',
...     app_secret='dskLLdkasdjlasdKK'
... )
NestedDict(
  ('code'): 0
  ('msg'): 'success'
  ('data'): NestedDict()
)
Source code in feishu/utils/request.py
Python
def patch(
    dest: str,
    data: Dict | None = None,
    params: Dict | None = None,
    headers: Dict | None = None,
    timeout: int = 120,
    token: str | None = None,
    app_id: str | None = None,
    app_secret: str | None = None,
    **kwargs,
) -> NestedDict:
    r"""
    向指定目的地发送 PUT 请求。

    Args:
        dest: 目的地统一资源定位符。这个地址应该是相对于飞书 API 的。
        headers: 请求头。默认为 `{}`。
        params: 请求参数。默认为 `{}`。
        timeout: 超时时间。默认为 120 秒。
        token: 访问凭证。如果为 `None`,则会自动获取。
            如果 token 为 `None`,则 app_id 和 app_secret 必须不为 `None`。
        app_id: 应用唯一标识(以`cli_`开头)。默认为 `None`。
        app_secret: 应用秘钥。默认为 `None`。

    Returns:
        请求结果

    Raises:
        ValueError: 如果 token, app_id, 和 app_secret 都为 `None`。

    Examples:
        >>> data = {"content": "{\"text\":\"test content\"}"}
        >>> patch(
        ...     'im/v1/messages/:message_id',
        ...     data=data,
        ...     app_id='cli_slkdjalasdkjasd',
        ...     app_secret='dskLLdkasdjlasdKK'
        ... )  # doctest:+SKIP
        NestedDict(
          ('code'): 0
          ('msg'): 'success'
          ('data'): NestedDict()
        )
    """
    return request(
        "PATCH",
        dest,
        data=data,
        params=params,
        headers=headers,
        timeout=timeout,
        token=token,
        app_id=app_id,
        app_secret=app_secret,
        **kwargs,
    )

delete

Python
delete(dest: str, data: Dict | None = None, params: Dict | None = None, headers: Dict | None = None, timeout: int = 120, token: str | None = None, app_id: str | None = None, app_secret: str | None = None, **kwargs) -> NestedDict

向指定目的地发送 DELETE 请求。

Parameters:

Name Type Description Default

dest

str

目的地统一资源定位符。这个地址应该是相对于飞书 API 的。

required

headers

Dict | None

请求头。默认为 {}

None

params

Dict | None

请求参数。默认为 {}

None

timeout

int

超时时间。默认为 120 秒。

120

token

str | None

访问凭证。如果为 None,则会自动获取。 如果 token 为 None,则 app_id 和 app_secret 必须不为 None

None

app_id

str | None

应用唯一标识(以cli_开头)。默认为 None

None

app_secret

str | None

应用秘钥。默认为 None

None

Returns:

Type Description
NestedDict

请求结果

Raises:

Type Description
ValueError

如果 token, app_id, 和 app_secret 都为 None

Examples:

Python Console Session
>>> delete(
...     'im/v1/messages/:message_id',
...     app_id='cli_slkdjalasdkjasd',
...     app_secret='dskLLdkasdjlasdKK'
... )
NestedDict(
  ('code'): 0
  ('msg'): 'success'
  ('data'): NestedDict()
)
Source code in feishu/utils/request.py
Python
def delete(
    dest: str,
    data: Dict | None = None,
    params: Dict | None = None,
    headers: Dict | None = None,
    timeout: int = 120,
    token: str | None = None,
    app_id: str | None = None,
    app_secret: str | None = None,
    **kwargs,
) -> NestedDict:
    r"""
    向指定目的地发送 DELETE 请求。

    Args:
        dest: 目的地统一资源定位符。这个地址应该是相对于飞书 API 的。
        headers: 请求头。默认为 `{}`。
        params: 请求参数。默认为 `{}`。
        timeout: 超时时间。默认为 120 秒。
        token: 访问凭证。如果为 `None`,则会自动获取。
            如果 token 为 `None`,则 app_id 和 app_secret 必须不为 `None`。
        app_id: 应用唯一标识(以`cli_`开头)。默认为 `None`。
        app_secret: 应用秘钥。默认为 `None`。

    Returns:
        请求结果

    Raises:
        ValueError: 如果 token, app_id, 和 app_secret 都为 `None`。

    Examples:
        >>> delete(
        ...     'im/v1/messages/:message_id',
        ...     app_id='cli_slkdjalasdkjasd',
        ...     app_secret='dskLLdkasdjlasdKK'
        ... )  # doctest:+SKIP
        NestedDict(
          ('code'): 0
          ('msg'): 'success'
          ('data'): NestedDict()
        )
    """
    return request(
        "DELETE",
        dest,
        data=data,
        params=params,
        headers=headers,
        timeout=timeout,
        token=token,
        app_id=app_id,
        app_secret=app_secret,
        **kwargs,
    )