Skip to content

Commit

Permalink
[twitter] improve error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
mikf committed Jan 22, 2022
1 parent 9a22149 commit 9ca8bb2
Showing 1 changed file with 23 additions and 15 deletions.
38 changes: 23 additions & 15 deletions gallery_dl/extractor/twitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -987,7 +987,7 @@ def _guest_token(self):
endpoint = "/1.1/guest/activate.json"
return str(self._call(endpoint, None, root, "POST")["guest_token"])

def _call(self, endpoint, params, root=None, method="GET"):
def _call(self, endpoint, params, root=None, method="GET", warning=True):
if root is None:
root = self.root

Expand All @@ -1012,6 +1012,8 @@ def _call(self, endpoint, params, root=None, method="GET"):

if response.status_code < 400:
# success
if errors and warning:
self.extractor.log.warning(errors)
return data

if response.status_code == 429:
Expand Down Expand Up @@ -1135,13 +1137,16 @@ def _pagination_tweets(self, endpoint, variables, path=None):
params = {"variables": json.dumps(variables)}
data = self._call(endpoint, params)["data"]

if path is None:
instructions = (data["user"]["result"]["timeline"]
["timeline"]["instructions"])
else:
for key in path:
data = data[key]
instructions = data["instructions"]
try:
if path is None:
instructions = (data["user"]["result"]["timeline"]
["timeline"]["instructions"])
else:
for key in path:
data = data[key]
instructions = data["instructions"]
except KeyError:
return

if pinned_tweet:
pinned_tweet = False
Expand Down Expand Up @@ -1214,13 +1219,16 @@ def _pagination_users(self, endpoint, variables, path=None):
params = {"variables": json.dumps(variables)}
data = self._call(endpoint, params)["data"]

if path is None:
instructions = (data["user"]["result"]["timeline"]
["timeline"]["instructions"])
else:
for key in path:
data = data[key]
instructions = data["instructions"]
try:
if path is None:
instructions = (data["user"]["result"]["timeline"]
["timeline"]["instructions"])
else:
for key in path:
data = data[key]
instructions = data["instructions"]
except KeyError:
return

for instr in instructions:
if instr["type"] == "TimelineAddEntries":
Expand Down

0 comments on commit 9ca8bb2

Please sign in to comment.