[twitter] improve error handling

pull/2243/head
Mike Fährmann 3 years ago
parent 9a221494c3
commit 9ca8bb2dc0
No known key found for this signature in database
GPG Key ID: 5680CA389D365A88

@ -987,7 +987,7 @@ class TwitterAPI():
endpoint = "/1.1/guest/activate.json" endpoint = "/1.1/guest/activate.json"
return str(self._call(endpoint, None, root, "POST")["guest_token"]) 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: if root is None:
root = self.root root = self.root
@ -1012,6 +1012,8 @@ class TwitterAPI():
if response.status_code < 400: if response.status_code < 400:
# success # success
if errors and warning:
self.extractor.log.warning(errors)
return data return data
if response.status_code == 429: if response.status_code == 429:
@ -1135,13 +1137,16 @@ class TwitterAPI():
params = {"variables": json.dumps(variables)} params = {"variables": json.dumps(variables)}
data = self._call(endpoint, params)["data"] data = self._call(endpoint, params)["data"]
if path is None: try:
instructions = (data["user"]["result"]["timeline"] if path is None:
["timeline"]["instructions"]) instructions = (data["user"]["result"]["timeline"]
else: ["timeline"]["instructions"])
for key in path: else:
data = data[key] for key in path:
instructions = data["instructions"] data = data[key]
instructions = data["instructions"]
except KeyError:
return
if pinned_tweet: if pinned_tweet:
pinned_tweet = False pinned_tweet = False
@ -1214,13 +1219,16 @@ class TwitterAPI():
params = {"variables": json.dumps(variables)} params = {"variables": json.dumps(variables)}
data = self._call(endpoint, params)["data"] data = self._call(endpoint, params)["data"]
if path is None: try:
instructions = (data["user"]["result"]["timeline"] if path is None:
["timeline"]["instructions"]) instructions = (data["user"]["result"]["timeline"]
else: ["timeline"]["instructions"])
for key in path: else:
data = data[key] for key in path:
instructions = data["instructions"] data = data[key]
instructions = data["instructions"]
except KeyError:
return
for instr in instructions: for instr in instructions:
if instr["type"] == "TimelineAddEntries": if instr["type"] == "TimelineAddEntries":

Loading…
Cancel
Save