From ff7c0b7effe4d8a50219fd7e134560e4fcf04756 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Thu, 2 Apr 2020 22:14:02 +0200 Subject: [PATCH] [deviantart] handle "Request blocked" errors (#655) - add a 2 second wait time between requests to deviantart.com - catch 403 "Request blocked" errors and wait for 3 minutes until retrying --- gallery_dl/extractor/deviantart.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/gallery_dl/extractor/deviantart.py b/gallery_dl/extractor/deviantart.py index d82b9485..bd1052de 100644 --- a/gallery_dl/extractor/deviantart.py +++ b/gallery_dl/extractor/deviantart.py @@ -1066,6 +1066,7 @@ class DeviantartOAuthAPI(): class DeviantartEclipseAPI(): """Interface to the DeviantArt Eclipse API""" + _last_request = 0 def __init__(self, extractor): self.extractor = extractor @@ -1102,6 +1103,10 @@ class DeviantartEclipseAPI(): return self._pagination(endpoint, params) def _call(self, endpoint, params=None): + diff = time.time() - DeviantartEclipseAPI._last_request + if diff < 2.0: + time.sleep(2.0 - diff) + url = "https://www.deviantart.com/_napi/" + endpoint headers = {"Referer": "https://www.deviantart.com/"} @@ -1114,8 +1119,8 @@ class DeviantartEclipseAPI(): raise exception.StopExtraction( "Your account must use the Eclipse interface.") elif code == 403 and b"Request blocked." in response.content: - raise exception.StopExtraction( - "Requests to deviantart.com blocked due to too much traffic.") + self.extractor.wait(seconds=180, reason="rate limit reset") + return self._call(endpoint, params) try: return response.json() except Exception: