mirror of
https://github.com/instaloader/instaloader.git
synced 2024-11-09 03:42:31 +01:00
Raise QueryReturnedNotFoundException if expected structure is missing
- QueryReturnedNotFoundException now inherits ConnectionException --> Retry on 404 errors + missing "window._sharedData" Relates to #146 and #496.
This commit is contained in:
parent
d3403bc686
commit
8764947d10
@ -9,10 +9,6 @@ class QueryReturnedBadRequestException(InstaloaderException):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class QueryReturnedNotFoundException(InstaloaderException):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class QueryReturnedForbiddenException(InstaloaderException):
|
class QueryReturnedForbiddenException(InstaloaderException):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@ -62,5 +58,9 @@ class PostChangedException(InstaloaderException):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class QueryReturnedNotFoundException(ConnectionException):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class TooManyRequestsException(ConnectionException):
|
class TooManyRequestsException(ConnectionException):
|
||||||
pass
|
pass
|
||||||
|
@ -397,7 +397,7 @@ class InstaloaderContext:
|
|||||||
if is_html_query:
|
if is_html_query:
|
||||||
match = re.search(r'window\._sharedData = (.*);</script>', resp.text)
|
match = re.search(r'window\._sharedData = (.*);</script>', resp.text)
|
||||||
if match is None:
|
if match is None:
|
||||||
raise ConnectionException("Could not find \"window._sharedData\" in html response.")
|
raise QueryReturnedNotFoundException("Could not find \"window._sharedData\" in html response.")
|
||||||
resp_json = json.loads(match.group(1))
|
resp_json = json.loads(match.group(1))
|
||||||
entry_data = resp_json.get('entry_data')
|
entry_data = resp_json.get('entry_data')
|
||||||
post_or_profile_page = list(entry_data.values())[0] if entry_data is not None else None
|
post_or_profile_page = list(entry_data.values())[0] if entry_data is not None else None
|
||||||
@ -422,6 +422,9 @@ class InstaloaderContext:
|
|||||||
except (ConnectionException, json.decoder.JSONDecodeError, requests.exceptions.RequestException) as err:
|
except (ConnectionException, json.decoder.JSONDecodeError, requests.exceptions.RequestException) as err:
|
||||||
error_string = "JSON Query to {}: {}".format(path, err)
|
error_string = "JSON Query to {}: {}".format(path, err)
|
||||||
if _attempt == self.max_connection_attempts:
|
if _attempt == self.max_connection_attempts:
|
||||||
|
if isinstance(err, QueryReturnedNotFoundException):
|
||||||
|
raise QueryReturnedNotFoundException(error_string) from err
|
||||||
|
else:
|
||||||
raise ConnectionException(error_string) from err
|
raise ConnectionException(error_string) from err
|
||||||
self.error(error_string + " [retrying; skip with ^C]", repeat_at_end=False)
|
self.error(error_string + " [retrying; skip with ^C]", repeat_at_end=False)
|
||||||
try:
|
try:
|
||||||
|
Loading…
Reference in New Issue
Block a user