[twitter] warn about suspended accounts etc (closes #1759)
This commit is contained in:
@@ -726,21 +726,25 @@ class TwitterAPI():
|
|||||||
if csrf_token:
|
if csrf_token:
|
||||||
self.headers["x-csrf-token"] = csrf_token
|
self.headers["x-csrf-token"] = csrf_token
|
||||||
|
|
||||||
|
data = response.json()
|
||||||
|
if "errors" in data:
|
||||||
|
try:
|
||||||
|
msg = ", ".join(
|
||||||
|
'"' + error["message"] + '"'
|
||||||
|
for error in data["errors"]
|
||||||
|
)
|
||||||
|
except Exception:
|
||||||
|
msg = data["errors"]
|
||||||
|
if response.status_code < 400:
|
||||||
|
self.extractor.log.warning(msg)
|
||||||
|
|
||||||
if response.status_code < 400:
|
if response.status_code < 400:
|
||||||
return response.json()
|
return data
|
||||||
if response.status_code == 429:
|
if response.status_code == 429:
|
||||||
until = response.headers.get("x-rate-limit-reset")
|
until = response.headers.get("x-rate-limit-reset")
|
||||||
seconds = None if until else 60
|
seconds = None if until else 60
|
||||||
self.extractor.wait(until=until, seconds=seconds)
|
self.extractor.wait(until=until, seconds=seconds)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
try:
|
|
||||||
msg = ", ".join(
|
|
||||||
'"' + error["message"] + '"'
|
|
||||||
for error in response.json()["errors"]
|
|
||||||
)
|
|
||||||
except Exception:
|
|
||||||
msg = response.text
|
|
||||||
raise exception.StopExtraction(
|
raise exception.StopExtraction(
|
||||||
"%s %s (%s)", response.status_code, response.reason, msg)
|
"%s %s (%s)", response.status_code, response.reason, msg)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user