@@ -56,16 +56,15 @@ class RateLimitInfo:
5656 Parsed rate limit information from HTTP response headers.
5757 """
5858
59- endpoint_group : str
6059 remaining : int
6160 reset_in_seconds : int
6261 limit : Optional [int ] = None
6362 window_seconds : Optional [int ] = None
6463
6564
6665# Regex patterns for parsing rate limit headers
67- # e.g.: "api";r=0;t=55 --> endpoint_group="api", r=0, t=55
68- _RATELIMIT_HEADER_REGEX = re .compile (r'"([^"]+)"\s*;\s* r\s*=\s*(\d+)\s*;\s*t\s*=\s*(\d+)' )
66+ # e.g.: "api";r=0;t=55 --> r=0, t=55
67+ _RATELIMIT_HEADER_REGEX = re .compile (r" r\s*=\s*(\d+)\s*;\s*t\s*=\s*(\d+)" )
6968# e.g.: "fixed window";"api";q=500;w=300 --> q=500, w=300
7069_RATELIMIT_POLICY_REGEX = re .compile (r"q\s*=\s*(\d+).*?w\s*=\s*(\d+)" )
7170
@@ -91,9 +90,8 @@ def parse_ratelimit_headers(headers: httpx.Headers) -> Optional[RateLimitInfo]:
9190 if not match :
9291 return None
9392
94- endpoint_group = match .group (1 )
95- remaining = int (match .group (2 ))
96- reset_in_seconds = int (match .group (3 ))
93+ remaining = int (match .group (1 ))
94+ reset_in_seconds = int (match .group (2 ))
9795
9896 limit : Optional [int ] = None
9997 window_seconds : Optional [int ] = None
@@ -106,7 +104,6 @@ def parse_ratelimit_headers(headers: httpx.Headers) -> Optional[RateLimitInfo]:
106104 window_seconds = int (policy_match .group (2 ))
107105
108106 return RateLimitInfo (
109- endpoint_group = endpoint_group ,
110107 remaining = remaining ,
111108 reset_in_seconds = reset_in_seconds ,
112109 limit = limit ,
@@ -688,15 +685,17 @@ def hf_raise_for_status(response: httpx.Response, endpoint_name: Optional[str] =
688685 elif response .status_code == 429 :
689686 ratelimit_info = parse_ratelimit_headers (response .headers )
690687 if ratelimit_info is not None :
691- message = f"\n \n 429 Too Many Requests. Rate limited on ' { ratelimit_info . endpoint_group } ' endpoint ."
692- message += f"\n Retry after { ratelimit_info .reset_in_seconds } seconds. "
688+ message = f"\n \n 429 Too Many Requests for url: { response . url } ."
689+ message += f"\n Retry after { ratelimit_info .reset_in_seconds } seconds"
693690 if ratelimit_info .limit is not None and ratelimit_info .window_seconds is not None :
694691 message += (
695- f" { ratelimit_info .remaining } /{ ratelimit_info .limit } requests remaining"
696- f" in current { ratelimit_info .window_seconds } s window."
692+ f" ( { ratelimit_info .remaining } /{ ratelimit_info .limit } requests remaining"
693+ f" in current { ratelimit_info .window_seconds } s window) ."
697694 )
695+ else :
696+ message += "."
698697 else :
699- message = "\n \n 429 Too Many Requests."
698+ message = f "\n \n 429 Too Many Requests for url: { response . url } ."
700699 raise _format (HfHubHTTPError , message , response ) from e
701700
702701 elif response .status_code == 416 :
0 commit comments