@@ -98,7 +98,8 @@ async def request(self, route: Route, **kwargs) -> Optional[Any]:
9898 """
9999
100100 kwargs ["headers" ] = {** self ._headers , ** kwargs .get ("headers" , {})}
101- kwargs ["headers" ]["Content-Type" ] = "application/json"
101+ if kwargs .get ("json" ):
102+ kwargs ["headers" ]["Content-Type" ] = "application/json"
102103
103104 reason = kwargs .pop ("reason" , None )
104105 if reason :
@@ -165,7 +166,7 @@ async def request(self, route: Route, **kwargs) -> Optional[Any]:
165166 # This "redundant" debug line is for debug use and tracing back the error codes.
166167
167168 raise HTTPException (data ["code" ], message = data ["message" ])
168- elif remaining and not int (remaining ):
169+ if remaining and not int (remaining ):
169170 if response .status == 429 :
170171 log .warning (
171172 f"The HTTP client has encountered a per-route ratelimit. Locking down future requests for { reset_after } seconds."
@@ -181,6 +182,18 @@ async def request(self, route: Route, **kwargs) -> Optional[Any]:
181182 self ._loop .call_later (
182183 self ._global_lock .reset_after , self ._global_lock .lock .release
183184 )
185+ elif int (remaining ) == 0 :
186+ log .warning (
187+ f"The HTTP client has exhausted a per-route ratelimit. Locking route for { reset_after } seconds."
188+ )
189+ self ._loop .call_later (reset_after , _limiter .release_lock ())
190+
191+ if response .status in {500 , 502 , 504 }:
192+ log .warning (
193+ f"{ route .endpoint } Received { response .status } ... retrying in { 1 + tries * 2 } seconds"
194+ )
195+ await asyncio .sleep (1 + tries * 2 )
196+ continue
184197
185198 log .debug (f"RETURN { response .status } : { dumps (data , indent = 4 , sort_keys = True )} " )
186199
0 commit comments