Catch a broader exception type in scrapers
This commit is contained in:
parent
05d6cd9c01
commit
b17bb1d687
2 changed files with 8 additions and 10 deletions
|
|
@ -54,7 +54,7 @@ async def _request_details(product_id: str) -> dict:
|
|||
response = await client.get(url, headers=HEADERS, follow_redirects=True, cookies=cookies)
|
||||
response.raise_for_status()
|
||||
return response.json()
|
||||
except httpx.NetworkError as ne:
|
||||
except httpx.HTTPError as ne:
|
||||
print(ne)
|
||||
api_details = None
|
||||
|
||||
|
|
|
|||
|
|
@ -36,24 +36,22 @@ def _get_package_size(data: dict) -> str:
|
|||
def _get_client() -> httpx.AsyncClient:
|
||||
return httpx.AsyncClient()
|
||||
|
||||
last_cookies = None
|
||||
cached_cookies = None
|
||||
async def _request_url(url: str) -> dict:
|
||||
global last_cookies
|
||||
global cached_cookies
|
||||
|
||||
async with _get_client() as client:
|
||||
if last_cookies:
|
||||
cookies = last_cookies
|
||||
else:
|
||||
cookies = await _get_cookies(client)
|
||||
last_cookies = cookies
|
||||
if not cached_cookies:
|
||||
cached_cookies = await _get_cookies(client)
|
||||
|
||||
cookies = cached_cookies
|
||||
try:
|
||||
response = await client.get(url, headers=HEADERS, follow_redirects=True, cookies=cookies)
|
||||
response.raise_for_status()
|
||||
return response.json()
|
||||
except httpx.NetworkError as ne:
|
||||
except httpx.HTTPError as ne:
|
||||
print(ne)
|
||||
last_cookies = None
|
||||
cached_cookies = None
|
||||
return None
|
||||
|
||||
def _get_product_details_url(product_id) -> str:
|
||||
|
|
|
|||
Loading…
Reference in a new issue