Skip to content

Commit

Permalink
Update library and fix issues arised
Browse files Browse the repository at this point in the history
  • Loading branch information
dolfies committed Dec 31, 2023
1 parent 0704df8 commit 0448e93
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 16 deletions.
19 changes: 4 additions & 15 deletions discord/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 0448e93

Please sign in to comment.