2022-04-24 12:38:09 +02:00
|
|
|
#!/usr/bin/env python
|
|
|
|
#
|
|
|
|
# A library that provides a Python interface to the Telegram Bot API
|
2023-01-01 21:31:29 +01:00
|
|
|
# Copyright (C) 2015-2023
|
2022-04-24 12:38:09 +02:00
|
|
|
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU Lesser Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU Lesser Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Lesser Public License
|
|
|
|
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
|
|
|
"""This module contains an abstract class to make POST and GET requests."""
|
|
|
|
import abc
|
2022-05-19 12:47:53 +02:00
|
|
|
import json
|
2022-04-24 12:38:09 +02:00
|
|
|
from http import HTTPStatus
|
|
|
|
from types import TracebackType
|
2023-06-29 18:17:47 +02:00
|
|
|
from typing import AsyncContextManager, Final, List, Optional, Tuple, Type, TypeVar, Union, final
|
2022-04-24 12:38:09 +02:00
|
|
|
|
2022-05-05 09:27:54 +02:00
|
|
|
from telegram._utils.defaultvalue import DEFAULT_NONE as _DEFAULT_NONE
|
2023-02-02 18:55:07 +01:00
|
|
|
from telegram._utils.defaultvalue import DefaultValue
|
2023-04-18 16:17:20 +02:00
|
|
|
from telegram._utils.logging import get_logger
|
2022-05-05 09:27:54 +02:00
|
|
|
from telegram._utils.types import JSONDict, ODVInput
|
2022-04-24 12:38:09 +02:00
|
|
|
from telegram._version import __version__ as ptb_ver
|
|
|
|
from telegram.error import (
|
|
|
|
BadRequest,
|
|
|
|
ChatMigrated,
|
|
|
|
Conflict,
|
2022-05-05 09:27:54 +02:00
|
|
|
Forbidden,
|
2022-04-24 12:38:09 +02:00
|
|
|
InvalidToken,
|
|
|
|
NetworkError,
|
|
|
|
RetryAfter,
|
2022-05-05 09:27:54 +02:00
|
|
|
TelegramError,
|
2022-04-24 12:38:09 +02:00
|
|
|
)
|
2022-05-05 09:27:54 +02:00
|
|
|
from telegram.request._requestdata import RequestData
|
2022-04-24 12:38:09 +02:00
|
|
|
|
|
|
|
RT = TypeVar("RT", bound="BaseRequest")
|
|
|
|
|
2023-04-18 16:17:20 +02:00
|
|
|
_LOGGER = get_logger(__name__, class_name="BaseRequest")
|
|
|
|
|
2022-04-24 12:38:09 +02:00
|
|
|
|
|
|
|
class BaseRequest(
|
2023-02-02 18:55:07 +01:00
|
|
|
AsyncContextManager["BaseRequest"],
|
2022-04-24 12:38:09 +02:00
|
|
|
abc.ABC,
|
|
|
|
):
|
|
|
|
"""Abstract interface class that allows python-telegram-bot to make requests to the Bot API.
|
|
|
|
Can be implemented via different asyncio HTTP libraries. An implementation of this class
|
|
|
|
must implement all abstract methods and properties.
|
|
|
|
|
|
|
|
Instances of this class can be used as asyncio context managers, where
|
|
|
|
|
|
|
|
.. code:: python
|
|
|
|
|
|
|
|
async with request_object:
|
|
|
|
# code
|
|
|
|
|
|
|
|
is roughly equivalent to
|
|
|
|
|
|
|
|
.. code:: python
|
|
|
|
|
|
|
|
try:
|
|
|
|
await request_object.initialize()
|
|
|
|
# code
|
|
|
|
finally:
|
|
|
|
await request_object.shutdown()
|
|
|
|
|
2023-10-09 18:59:52 +02:00
|
|
|
.. seealso:: :meth:`__aenter__` and :meth:`__aexit__`.
|
|
|
|
|
2022-06-01 21:26:18 +02:00
|
|
|
Tip:
|
|
|
|
JSON encoding and decoding is done with the standard library's :mod:`json` by default.
|
|
|
|
To use a custom library for this, you can override :meth:`parse_json_payload` and implement
|
|
|
|
custom logic to encode the keys of :attr:`telegram.request.RequestData.parameters`.
|
|
|
|
|
2023-01-01 16:24:00 +01:00
|
|
|
.. seealso:: :wiki:`Architecture Overview <Architecture>`,
|
|
|
|
:wiki:`Builder Pattern <Builder-Pattern>`
|
Documentation Improvements (#3214, #3217, #3218, #3271, #3289, #3292, #3303, #3312, #3306, #3319, #3326, #3314)
Co-authored-by: Harshil <37377066+harshil21@users.noreply.github.com>
Co-authored-by: Simon Fong <44134941+simonfongnt@users.noreply.github.com>
Co-authored-by: Piotr Rogulski <rivinek@gmail.com>
Co-authored-by: poolitzer <25934244+Poolitzer@users.noreply.github.com>
Co-authored-by: Or Bin <or@raftt.io>
Co-authored-by: Sandro <j32g7f67hb@liamekaens.com>
Co-authored-by: Hatim Zahid <63000127+HatimZ@users.noreply.github.com>
Co-authored-by: Robi <53259730+RobiMez@users.noreply.github.com>
Co-authored-by: Dmitry Kolomatskiy <58207913+lemontree210@users.noreply.github.com>
2022-11-15 09:06:23 +01:00
|
|
|
|
2022-05-06 17:15:23 +02:00
|
|
|
.. versionadded:: 20.0
|
2022-04-24 12:38:09 +02:00
|
|
|
"""
|
|
|
|
|
|
|
|
__slots__ = ()
|
|
|
|
|
2023-06-29 18:17:47 +02:00
|
|
|
USER_AGENT: Final[str] = f"python-telegram-bot v{ptb_ver} (https://python-telegram-bot.org)"
|
2022-04-24 12:38:09 +02:00
|
|
|
""":obj:`str`: A description that can be used as user agent for requests made to the Bot API.
|
|
|
|
"""
|
2023-06-29 18:17:47 +02:00
|
|
|
DEFAULT_NONE: Final[DefaultValue[None]] = _DEFAULT_NONE
|
2022-04-24 12:38:09 +02:00
|
|
|
""":class:`object`: A special object that indicates that an argument of a function was not
|
|
|
|
explicitly passed. Used for the timeout parameters of :meth:`post` and :meth:`do_request`.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
When calling ``request.post(url)``, ``request`` should use the default timeouts set on
|
|
|
|
initialization. When calling ``request.post(url, connect_timeout=5, read_timeout=None)``,
|
|
|
|
``request`` should use ``5`` for the connect timeout and :obj:`None` for the read timeout.
|
|
|
|
|
|
|
|
Use ``if parameter is (not) BaseRequest.DEFAULT_NONE:`` to check if the parameter was set.
|
|
|
|
"""
|
|
|
|
|
|
|
|
async def __aenter__(self: RT) -> RT:
|
2023-10-09 18:59:52 +02:00
|
|
|
"""|async_context_manager| :meth:`initializes <initialize>` the Request.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
The initialized Request instance.
|
|
|
|
|
|
|
|
Raises:
|
|
|
|
:exc:`Exception`: If an exception is raised during initialization, :meth:`shutdown`
|
|
|
|
is called in this case.
|
|
|
|
"""
|
2022-04-24 12:38:09 +02:00
|
|
|
try:
|
|
|
|
await self.initialize()
|
|
|
|
return self
|
|
|
|
except Exception as exc:
|
|
|
|
await self.shutdown()
|
|
|
|
raise exc
|
|
|
|
|
|
|
|
async def __aexit__(
|
|
|
|
self,
|
|
|
|
exc_type: Optional[Type[BaseException]],
|
|
|
|
exc_val: Optional[BaseException],
|
|
|
|
exc_tb: Optional[TracebackType],
|
|
|
|
) -> None:
|
2023-10-09 18:59:52 +02:00
|
|
|
"""|async_context_manager| :meth:`shuts down <shutdown>` the Request."""
|
2022-04-24 12:38:09 +02:00
|
|
|
# Make sure not to return `True` so that exceptions are not suppressed
|
|
|
|
# https://docs.python.org/3/reference/datamodel.html?#object.__aexit__
|
|
|
|
await self.shutdown()
|
|
|
|
|
|
|
|
@abc.abstractmethod
|
|
|
|
async def initialize(self) -> None:
|
|
|
|
"""Initialize resources used by this class. Must be implemented by a subclass."""
|
|
|
|
|
|
|
|
@abc.abstractmethod
|
|
|
|
async def shutdown(self) -> None:
|
|
|
|
"""Stop & clear resources used by this class. Must be implemented by a subclass."""
|
|
|
|
|
2023-06-29 18:17:47 +02:00
|
|
|
@final
|
2022-04-24 12:38:09 +02:00
|
|
|
async def post(
|
|
|
|
self,
|
|
|
|
url: str,
|
2023-05-18 07:57:59 +02:00
|
|
|
request_data: Optional[RequestData] = None,
|
2022-04-24 12:38:09 +02:00
|
|
|
read_timeout: ODVInput[float] = DEFAULT_NONE,
|
|
|
|
write_timeout: ODVInput[float] = DEFAULT_NONE,
|
|
|
|
connect_timeout: ODVInput[float] = DEFAULT_NONE,
|
|
|
|
pool_timeout: ODVInput[float] = DEFAULT_NONE,
|
2022-12-15 15:00:36 +01:00
|
|
|
) -> Union[JSONDict, List[JSONDict], bool]:
|
2022-04-24 12:38:09 +02:00
|
|
|
"""Makes a request to the Bot API handles the return code and parses the answer.
|
|
|
|
|
|
|
|
Warning:
|
|
|
|
This method will be called by the methods of :class:`telegram.Bot` and should *not* be
|
|
|
|
called manually.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
url (:obj:`str`): The URL to request.
|
|
|
|
request_data (:class:`telegram.request.RequestData`, optional): An object containing
|
|
|
|
information about parameters and files to upload for the request.
|
|
|
|
read_timeout (:obj:`float` | :obj:`None`, optional): If passed, specifies the maximum
|
|
|
|
amount of time (in seconds) to wait for a response from Telegram's server instead
|
|
|
|
of the time specified during creating of this object. Defaults to
|
|
|
|
:attr:`DEFAULT_NONE`.
|
|
|
|
write_timeout (:obj:`float` | :obj:`None`, optional): If passed, specifies the maximum
|
|
|
|
amount of time (in seconds) to wait for a write operation to complete (in terms of
|
|
|
|
a network socket; i.e. POSTing a request or uploading a file) instead of the time
|
|
|
|
specified during creating of this object. Defaults to :attr:`DEFAULT_NONE`.
|
|
|
|
connect_timeout (:obj:`float` | :obj:`None`, optional): If passed, specifies the
|
|
|
|
maximum amount of time (in seconds) to wait for a connection attempt to a server
|
|
|
|
to succeed instead of the time specified during creating of this object. Defaults
|
|
|
|
to :attr:`DEFAULT_NONE`.
|
|
|
|
pool_timeout (:obj:`float` | :obj:`None`, optional): If passed, specifies the maximum
|
|
|
|
amount of time (in seconds) to wait for a connection to become available instead
|
|
|
|
of the time specified during creating of this object. Defaults to
|
|
|
|
:attr:`DEFAULT_NONE`.
|
|
|
|
|
|
|
|
Returns:
|
2022-12-15 15:00:36 +01:00
|
|
|
The JSON response of the Bot API.
|
2022-04-24 12:38:09 +02:00
|
|
|
|
|
|
|
"""
|
|
|
|
result = await self._request_wrapper(
|
|
|
|
url=url,
|
|
|
|
method="POST",
|
|
|
|
request_data=request_data,
|
|
|
|
read_timeout=read_timeout,
|
|
|
|
write_timeout=write_timeout,
|
|
|
|
connect_timeout=connect_timeout,
|
|
|
|
pool_timeout=pool_timeout,
|
|
|
|
)
|
2022-06-01 21:26:18 +02:00
|
|
|
json_data = self.parse_json_payload(result)
|
2022-04-24 12:38:09 +02:00
|
|
|
# For successful requests, the results are in the 'result' entry
|
|
|
|
# see https://core.telegram.org/bots/api#making-requests
|
|
|
|
return json_data["result"]
|
|
|
|
|
2023-06-29 18:17:47 +02:00
|
|
|
@final
|
2022-04-24 12:38:09 +02:00
|
|
|
async def retrieve(
|
|
|
|
self,
|
|
|
|
url: str,
|
|
|
|
read_timeout: ODVInput[float] = DEFAULT_NONE,
|
|
|
|
write_timeout: ODVInput[float] = DEFAULT_NONE,
|
|
|
|
connect_timeout: ODVInput[float] = DEFAULT_NONE,
|
|
|
|
pool_timeout: ODVInput[float] = DEFAULT_NONE,
|
|
|
|
) -> bytes:
|
|
|
|
"""Retrieve the contents of a file by its URL.
|
|
|
|
|
|
|
|
Warning:
|
|
|
|
This method will be called by the methods of :class:`telegram.Bot` and should *not* be
|
|
|
|
called manually.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
url (:obj:`str`): The web location we want to retrieve.
|
|
|
|
read_timeout (:obj:`float` | :obj:`None`, optional): If passed, specifies the maximum
|
|
|
|
amount of time (in seconds) to wait for a response from Telegram's server instead
|
|
|
|
of the time specified during creating of this object. Defaults to
|
|
|
|
:attr:`DEFAULT_NONE`.
|
|
|
|
write_timeout (:obj:`float` | :obj:`None`, optional): If passed, specifies the maximum
|
|
|
|
amount of time (in seconds) to wait for a write operation to complete (in terms of
|
|
|
|
a network socket; i.e. POSTing a request or uploading a file) instead of the time
|
|
|
|
specified during creating of this object. Defaults to :attr:`DEFAULT_NONE`.
|
|
|
|
connect_timeout (:obj:`float` | :obj:`None`, optional): If passed, specifies the
|
|
|
|
maximum amount of time (in seconds) to wait for a connection attempt to a server
|
|
|
|
to succeed instead of the time specified during creating of this object. Defaults
|
|
|
|
to :attr:`DEFAULT_NONE`.
|
|
|
|
pool_timeout (:obj:`float` | :obj:`None`, optional): If passed, specifies the maximum
|
|
|
|
amount of time (in seconds) to wait for a connection to become available instead
|
|
|
|
of the time specified during creating of this object. Defaults to
|
|
|
|
:attr:`DEFAULT_NONE`.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
:obj:`bytes`: The files contents.
|
|
|
|
|
|
|
|
"""
|
|
|
|
return await self._request_wrapper(
|
|
|
|
url=url,
|
|
|
|
method="GET",
|
|
|
|
read_timeout=read_timeout,
|
|
|
|
write_timeout=write_timeout,
|
|
|
|
connect_timeout=connect_timeout,
|
|
|
|
pool_timeout=pool_timeout,
|
|
|
|
)
|
|
|
|
|
|
|
|
async def _request_wrapper(
|
|
|
|
self,
|
|
|
|
url: str,
|
|
|
|
method: str,
|
2023-05-18 07:57:59 +02:00
|
|
|
request_data: Optional[RequestData] = None,
|
2022-04-24 12:38:09 +02:00
|
|
|
read_timeout: ODVInput[float] = DEFAULT_NONE,
|
|
|
|
write_timeout: ODVInput[float] = DEFAULT_NONE,
|
|
|
|
connect_timeout: ODVInput[float] = DEFAULT_NONE,
|
|
|
|
pool_timeout: ODVInput[float] = DEFAULT_NONE,
|
|
|
|
) -> bytes:
|
|
|
|
"""Wraps the real implementation request method.
|
|
|
|
|
|
|
|
Performs the following tasks:
|
|
|
|
* Handle the various HTTP response codes.
|
|
|
|
* Parse the Telegram server response.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
url (:obj:`str`): The URL to request.
|
|
|
|
method (:obj:`str`): HTTP method (i.e. 'POST', 'GET', etc.).
|
|
|
|
request_data (:class:`telegram.request.RequestData`, optional): An object containing
|
|
|
|
information about parameters and files to upload for the request.
|
|
|
|
read_timeout (:obj:`float` | :obj:`None`, optional): If passed, specifies the maximum
|
|
|
|
amount of time (in seconds) to wait for a response from Telegram's server instead
|
|
|
|
of the time specified during creating of this object. Defaults to
|
|
|
|
:attr:`DEFAULT_NONE`.
|
|
|
|
write_timeout (:obj:`float` | :obj:`None`, optional): If passed, specifies the maximum
|
|
|
|
amount of time (in seconds) to wait for a write operation to complete (in terms of
|
|
|
|
a network socket; i.e. POSTing a request or uploading a file) instead of the time
|
|
|
|
specified during creating of this object. Defaults to :attr:`DEFAULT_NONE`.
|
|
|
|
connect_timeout (:obj:`float` | :obj:`None`, optional): If passed, specifies the
|
|
|
|
maximum amount of time (in seconds) to wait for a connection attempt to a server
|
|
|
|
to succeed instead of the time specified during creating of this object. Defaults
|
|
|
|
to :attr:`DEFAULT_NONE`.
|
|
|
|
pool_timeout (:obj:`float` | :obj:`None`, optional): If passed, specifies the maximum
|
|
|
|
amount of time (in seconds) to wait for a connection to become available instead
|
|
|
|
of the time specified during creating of this object. Defaults to
|
|
|
|
:attr:`DEFAULT_NONE`.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
bytes: The payload part of the HTTP server response.
|
|
|
|
|
|
|
|
Raises:
|
|
|
|
TelegramError
|
|
|
|
|
|
|
|
"""
|
|
|
|
# TGs response also has the fields 'ok' and 'error_code'.
|
|
|
|
# However, we rather rely on the HTTP status code for now.
|
|
|
|
|
|
|
|
try:
|
|
|
|
code, payload = await self.do_request(
|
|
|
|
url=url,
|
|
|
|
method=method,
|
|
|
|
request_data=request_data,
|
|
|
|
read_timeout=read_timeout,
|
|
|
|
write_timeout=write_timeout,
|
|
|
|
connect_timeout=connect_timeout,
|
|
|
|
pool_timeout=pool_timeout,
|
|
|
|
)
|
|
|
|
except TelegramError as exc:
|
|
|
|
raise exc
|
|
|
|
except Exception as exc:
|
2023-06-07 21:51:40 +02:00
|
|
|
raise NetworkError(f"Unknown error in HTTP implementation: {exc!r}") from exc
|
2022-04-24 12:38:09 +02:00
|
|
|
|
|
|
|
if HTTPStatus.OK <= code <= 299:
|
|
|
|
# 200-299 range are HTTP success statuses
|
|
|
|
return payload
|
|
|
|
|
2022-06-01 21:26:18 +02:00
|
|
|
response_data = self.parse_json_payload(payload)
|
2022-04-24 12:38:09 +02:00
|
|
|
|
|
|
|
description = response_data.get("description")
|
2023-03-25 19:18:04 +01:00
|
|
|
message = description if description else "Unknown HTTPError"
|
2022-04-24 12:38:09 +02:00
|
|
|
|
|
|
|
# In some special cases, we can raise more informative exceptions:
|
|
|
|
# see https://core.telegram.org/bots/api#responseparameters and
|
|
|
|
# https://core.telegram.org/bots/api#making-requests
|
|
|
|
parameters = response_data.get("parameters")
|
|
|
|
if parameters:
|
|
|
|
migrate_to_chat_id = parameters.get("migrate_to_chat_id")
|
|
|
|
if migrate_to_chat_id:
|
|
|
|
raise ChatMigrated(migrate_to_chat_id)
|
|
|
|
retry_after = parameters.get("retry_after")
|
|
|
|
if retry_after:
|
|
|
|
raise RetryAfter(retry_after)
|
|
|
|
|
|
|
|
message += f"\nThe server response contained unknown parameters: {parameters}"
|
|
|
|
|
2022-08-03 08:16:48 +02:00
|
|
|
if code == HTTPStatus.FORBIDDEN: # 403
|
2022-04-24 12:38:09 +02:00
|
|
|
raise Forbidden(message)
|
2022-08-03 08:16:48 +02:00
|
|
|
if code in (HTTPStatus.NOT_FOUND, HTTPStatus.UNAUTHORIZED): # 404 and 401
|
2022-04-24 12:38:09 +02:00
|
|
|
# TG returns 404 Not found for
|
|
|
|
# 1) malformed tokens
|
|
|
|
# 2) correct tokens but non-existing method, e.g. api.tg.org/botTOKEN/unkonwnMethod
|
|
|
|
# We can basically rule out 2) since we don't let users make requests manually
|
|
|
|
# TG returns 401 Unauthorized for correctly formatted tokens that are not valid
|
|
|
|
raise InvalidToken(message)
|
2022-08-03 08:16:48 +02:00
|
|
|
if code == HTTPStatus.BAD_REQUEST: # 400
|
2022-04-24 12:38:09 +02:00
|
|
|
raise BadRequest(message)
|
2022-08-03 08:16:48 +02:00
|
|
|
if code == HTTPStatus.CONFLICT: # 409
|
2022-04-24 12:38:09 +02:00
|
|
|
raise Conflict(message)
|
2022-08-03 08:16:48 +02:00
|
|
|
if code == HTTPStatus.BAD_GATEWAY: # 502
|
2022-04-24 12:38:09 +02:00
|
|
|
raise NetworkError(description or "Bad Gateway")
|
|
|
|
raise NetworkError(f"{message} ({code})")
|
|
|
|
|
|
|
|
@staticmethod
|
2022-06-01 21:26:18 +02:00
|
|
|
def parse_json_payload(payload: bytes) -> JSONDict:
|
|
|
|
"""Parse the JSON returned from Telegram.
|
|
|
|
|
|
|
|
Tip:
|
|
|
|
By default, this method uses the standard library's :func:`json.loads` and
|
|
|
|
``errors="replace"`` in :meth:`bytes.decode`.
|
|
|
|
You can override it to customize either of these behaviors.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
payload (:obj:`bytes`): The UTF-8 encoded JSON payload as returned by Telegram.
|
2022-04-24 12:38:09 +02:00
|
|
|
|
|
|
|
Returns:
|
|
|
|
dict: A JSON parsed as Python dict with results.
|
|
|
|
|
|
|
|
Raises:
|
2022-06-01 21:26:18 +02:00
|
|
|
TelegramError: If loading the JSON data failed
|
2022-04-24 12:38:09 +02:00
|
|
|
"""
|
2022-06-01 21:26:18 +02:00
|
|
|
decoded_s = payload.decode("utf-8", "replace")
|
2022-04-24 12:38:09 +02:00
|
|
|
try:
|
|
|
|
return json.loads(decoded_s)
|
|
|
|
except ValueError as exc:
|
2023-04-18 16:17:20 +02:00
|
|
|
_LOGGER.error('Can not load invalid JSON data: "%s"', decoded_s)
|
2022-04-24 12:38:09 +02:00
|
|
|
raise TelegramError("Invalid server response") from exc
|
|
|
|
|
|
|
|
@abc.abstractmethod
|
|
|
|
async def do_request(
|
|
|
|
self,
|
|
|
|
url: str,
|
|
|
|
method: str,
|
2023-05-18 07:57:59 +02:00
|
|
|
request_data: Optional[RequestData] = None,
|
2022-04-24 12:38:09 +02:00
|
|
|
read_timeout: ODVInput[float] = DEFAULT_NONE,
|
|
|
|
write_timeout: ODVInput[float] = DEFAULT_NONE,
|
|
|
|
connect_timeout: ODVInput[float] = DEFAULT_NONE,
|
|
|
|
pool_timeout: ODVInput[float] = DEFAULT_NONE,
|
|
|
|
) -> Tuple[int, bytes]:
|
|
|
|
"""Makes a request to the Bot API. Must be implemented by a subclass.
|
|
|
|
|
|
|
|
Warning:
|
|
|
|
This method will be called by :meth:`post` and :meth:`retrieve`. It should *not* be
|
|
|
|
called manually.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
url (:obj:`str`): The URL to request.
|
|
|
|
method (:obj:`str`): HTTP method (i.e. ``'POST'``, ``'GET'``, etc.).
|
|
|
|
request_data (:class:`telegram.request.RequestData`, optional): An object containing
|
|
|
|
information about parameters and files to upload for the request.
|
|
|
|
read_timeout (:obj:`float` | :obj:`None`, optional): If passed, specifies the maximum
|
|
|
|
amount of time (in seconds) to wait for a response from Telegram's server instead
|
|
|
|
of the time specified during creating of this object. Defaults to
|
|
|
|
:attr:`DEFAULT_NONE`.
|
|
|
|
write_timeout (:obj:`float` | :obj:`None`, optional): If passed, specifies the maximum
|
|
|
|
amount of time (in seconds) to wait for a write operation to complete (in terms of
|
|
|
|
a network socket; i.e. POSTing a request or uploading a file) instead of the time
|
|
|
|
specified during creating of this object. Defaults to :attr:`DEFAULT_NONE`.
|
|
|
|
connect_timeout (:obj:`float` | :obj:`None`, optional): If passed, specifies the
|
|
|
|
maximum amount of time (in seconds) to wait for a connection attempt to a server
|
|
|
|
to succeed instead of the time specified during creating of this object. Defaults
|
|
|
|
to :attr:`DEFAULT_NONE`.
|
|
|
|
pool_timeout (:obj:`float` | :obj:`None`, optional): If passed, specifies the maximum
|
|
|
|
amount of time (in seconds) to wait for a connection to become available instead
|
|
|
|
of the time specified during creating of this object. Defaults to
|
|
|
|
:attr:`DEFAULT_NONE`.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Tuple[:obj:`int`, :obj:`bytes`]: The HTTP return code & the payload part of the server
|
|
|
|
response.
|
|
|
|
"""
|