MCPcopy Index your code
hub / github.com/python-telegram-bot/python-telegram-bot / do_api_request

Method do_api_request

src/telegram/_bot.py:886–988  ·  view source on GitHub ↗

Do a request to the Telegram API. This method is here to make it easier to use new API methods that are not yet supported by this library. Hint: Since PTB does not know which arguments are passed to this method, some caution is necessary in terms of

(
        self,
        endpoint: str,
        api_kwargs: JSONDict | None = None,
        return_type: type[TelegramObject] | None = None,
        *,
        read_timeout: ODVInput[float] = DEFAULT_NONE,
        write_timeout: ODVInput[float] = DEFAULT_NONE,
        connect_timeout: ODVInput[float] = DEFAULT_NONE,
        pool_timeout: ODVInput[float] = DEFAULT_NONE,
    )

Source from the content-addressed store, hash-verified

884 self._bot_initialized = False
885
886 async def do_api_request(
887 self,
888 endpoint: str,
889 api_kwargs: JSONDict | None = None,
890 return_type: type[TelegramObject] | None = None,
891 *,
892 read_timeout: ODVInput[float] = DEFAULT_NONE,
893 write_timeout: ODVInput[float] = DEFAULT_NONE,
894 connect_timeout: ODVInput[float] = DEFAULT_NONE,
895 pool_timeout: ODVInput[float] = DEFAULT_NONE,
896 ) -> Any:
897 """Do a request to the Telegram API.
898
899 This method is here to make it easier to use new API methods that are not yet supported
900 by this library.
901
902 Hint:
903 Since PTB does not know which arguments are passed to this method, some caution is
904 necessary in terms of PTBs utility functionalities. In particular
905
906 * passing objects of any class defined in the :mod:`telegram` module is supported
907 * when uploading files, a :class:`telegram.InputFile` must be passed as the value for
908 the corresponding argument. Passing a file path or file-like object will not work.
909 File paths will work only in combination with :paramref:`~Bot.local_mode`.
910 * when uploading files, PTB can still correctly determine that
911 a special write timeout value should be used instead of the default
912 :paramref:`telegram.request.HTTPXRequest.write_timeout`.
913 * insertion of default values specified via :class:`telegram.ext.Defaults` will not
914 work (only relevant for :class:`telegram.ext.ExtBot`).
915 * The only exception is :class:`telegram.ext.Defaults.tzinfo`, which will be correctly
916 applied to :class:`datetime.datetime` objects.
917
918 .. versionadded:: 20.8
919
920 Args:
921 endpoint (:obj:`str`): The API endpoint to use, e.g. ``getMe`` or ``get_me``.
922 api_kwargs (:obj:`dict`, optional): The keyword arguments to pass to the API call.
923 If not specified, no arguments are passed.
924 return_type (:class:`telegram.TelegramObject`, optional): If specified, the result of
925 the API call will be deserialized into an instance of this class or tuple of
926 instances of this class. If not specified, the raw result of the API call will be
927 returned.
928
929 Keyword Args:
930 read_timeout (:obj:`float` | :obj:`None`, optional): Value to pass to
931 :paramref:`telegram.request.BaseRequest.post.read_timeout`. Defaults to
932 :attr:`~telegram.request.BaseRequest.DEFAULT_NONE`.
933 write_timeout (:obj:`float` | :obj:`None`, optional): Value to pass to
934 :paramref:`telegram.request.BaseRequest.post.write_timeout`. Defaults to
935 :attr:`~telegram.request.BaseRequest.DEFAULT_NONE`.
936 connect_timeout (:obj:`float` | :obj:`None`, optional): Value to pass to
937 :paramref:`telegram.request.BaseRequest.post.connect_timeout`. Defaults to
938 :attr:`~telegram.request.BaseRequest.DEFAULT_NONE`.
939 pool_timeout (:obj:`float` | :obj:`None`, optional): Value to pass to
940 :paramref:`telegram.request.BaseRequest.post.pool_timeout`. Defaults to
941 :attr:`~telegram.request.BaseRequest.DEFAULT_NONE`.
942
943 Returns:

Calls 7

_warnMethod · 0.95
_postMethod · 0.95
to_camel_caseFunction · 0.90
EndPointNotFoundClass · 0.90
InvalidTokenClass · 0.90
de_listMethod · 0.80
de_jsonMethod · 0.45