lljz66 commited on
Commit
6066f54
·
verified ·
1 Parent(s): 097cfcc

Upload google_play_scraper/utils/http_utils.py

Browse files
google_play_scraper/utils/http_utils.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """HTTP Client with retries and delays."""
2
+ import time
3
+ import requests
4
+ from typing import Dict
5
+ from google_play_scraper.config.settings import SETTINGS
6
+ from google_play_scraper.exceptions import RateLimitError, RequestError
7
+
8
+
9
+ session = requests.Session()
10
+
11
+
12
+ def get(url: str, retries: int = 3, delay: float = 1.0) -> Dict:
13
+ """Make GET request with retries."""
14
+ for attempt in range(retries):
15
+ try:
16
+ response = session.get(url, timeout=SETTINGS["timeout"])
17
+ response.raise_for_status()
18
+ return response.json()
19
+ except requests.exceptions.HTTPError as e:
20
+ if response.status_code == 429:
21
+ raise RateLimitError("Rate limit exceeded")
22
+ raise RequestError(f"HTTP error: {e}")
23
+ except requests.exceptions.RequestException as e:
24
+ if attempt == retries - 1:
25
+ raise RequestError(f"Request failed: {e}")
26
+ time.sleep(delay)
27
+ return {}