1
0
mirror of https://github.com/eternnoir/pyTelegramBotAPI.git synced 2023-08-10 21:12:57 +03:00

Merge pull request #1913 from coder2020official/botapi6.5

Fix #1912
This commit is contained in:
_run 2023-02-09 19:49:17 +04:00 committed by GitHub
commit fb7d60f09d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -184,7 +184,7 @@ async def download_file(token, file_path):
session = await session_manager.get_session() session = await session_manager.get_session()
async with session.get(url, proxy=proxy) as response: async with session.get(url, proxy=proxy) as response:
if response.status != 200: if response.status != 200:
raise ApiHTTPException('Download file', result) raise ApiHTTPException('Download file', response)
result = await response.read() result = await response.read()
return result return result
@ -247,7 +247,7 @@ async def get_updates(token, offset=None, limit=None,
params['allowed_updates'] = json.dumps(allowed_updates) params['allowed_updates'] = json.dumps(allowed_updates)
return await _process_request(token, method_name, params=params, request_timeout=request_timeout) return await _process_request(token, method_name, params=params, request_timeout=request_timeout)
async def _check_result(method_name, result): async def _check_result(method_name, result: aiohttp.ClientResponse):
""" """
Checks whether `result` is a valid API response. Checks whether `result` is a valid API response.
A result is considered invalid if: A result is considered invalid if:
@ -263,7 +263,7 @@ async def _check_result(method_name, result):
try: try:
result_json = await result.json(encoding="utf-8") result_json = await result.json(encoding="utf-8")
except: except:
if result.status_code != 200: if result.status != 200:
raise ApiHTTPException(method_name, result) raise ApiHTTPException(method_name, result)
else: else:
raise ApiInvalidJSONException(method_name, result) raise ApiInvalidJSONException(method_name, result)
@ -1898,10 +1898,10 @@ class ApiHTTPException(ApiException):
This class represents an Exception thrown when a call to the This class represents an Exception thrown when a call to the
Telegram API server returns HTTP code that is not 200. Telegram API server returns HTTP code that is not 200.
""" """
def __init__(self, function_name, result): def __init__(self, function_name, result: aiohttp.ClientResponse):
super(ApiHTTPException, self).__init__( super(ApiHTTPException, self).__init__(
"The server returned HTTP {0} {1}. Response body:\n[{2}]" \ "The server returned HTTP {0} {1}. Response body:\n[{2}]" \
.format(result.status_code, result.reason, result), .format(result.status, result.reason, result.request_info),
function_name, function_name,
result) result)