From 0448e933cc6c6b9f69d3c90a87adc6a269980a7a Mon Sep 17 00:00:00 2001 From: dolfies Date: Sun, 31 Dec 2023 14:54:22 -0500 Subject: [PATCH] Update library and fix issues arised --- discord/http.py | 19 ++++--------------- requirements.txt | 2 +- 2 files changed, 5 insertions(+), 16 deletions(-) diff --git a/discord/http.py b/discord/http.py index 22bc24c37552..c917de5c7b7d 100644 --- a/discord/http.py +++ b/discord/http.py @@ -27,10 +27,8 @@ import asyncio import datetime import logging -import platform import ssl import string -import sys from collections import deque from http import HTTPStatus from random import choice, choices @@ -168,10 +166,6 @@ def _gen_accept_encoding_header(): # aiohttp does it for us on newer versions anyway pass -# Required for curl_cffi to work unfortunately -if platform.system() == 'Windows' and sys.version_info >= (3, 8): - asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy()) # type: ignore # Does not exist on non-Windows platforms - async def json_or_text(response: Union[aiohttp.ClientResponse, requests.Response]) -> Union[Dict[str, Any], str]: if isinstance(response, aiohttp.ClientResponse): @@ -648,9 +642,6 @@ async def startup(self) -> None: impersonate = max(chromes, key=lambda c: int(c[6:].split('_')[0])) self.__session = requests.AsyncSession(impersonate=impersonate) - if self.captcha_handler is not None: - await self.captcha_handler.startup() - self._started = True async def ws_connect(self, url: str, *, compress: int = 0) -> aiohttp.ClientWebSocketResponse: @@ -858,7 +849,7 @@ async def request( ) # 202s must be retried - if response.status == 202 and isinstance(data, dict) and data['code'] == 110000: + if response.status_code == 202 and isinstance(data, dict) and data['code'] == 110000: # We update the `attempts` query parameter params = kwargs.get('params') if not params: @@ -960,10 +951,8 @@ async def request( # libcurl errors except requests.RequestsError as e: - if not getattr(e, 'code', None): - # Outdated library or not an HTTP exception - raise - if e.code in (23, 28, 35): + # Outdated library might be missing the code + if getattr(e, 'code', None) in (23, 28, 35): failed += 1 await asyncio.sleep(1 + tries * 2) continue @@ -1026,7 +1015,7 @@ async def upload_to_cloud(self, url: str, file: Union[File, str], hash: Optional return data # Unconditional retry - if response.status in {500, 502, 504}: + if response.status in {500, 502, 504, 507, 522, 523, 524}: await asyncio.sleep(1 + tries * 2) continue diff --git a/requirements.txt b/requirements.txt index 780683f39d0a..e7d0429443df 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ aiohttp>=3.7.4,<4 -curl_cffi>=0.5.7 +curl_cffi>=0.6.0b7,<1 tzlocal>=4.0.0,<6 discord_protos<1.0.0