Skip to content

Commit

Permalink
[pixiv] wait and retry after rate limit error (closes #535)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikf committed Dec 28, 2019
1 parent 6b373cb commit a27f43d
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions gallery_dl/extractor/pixiv.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from ..cache import cache
from datetime import datetime, timedelta
import hashlib
import time


class PixivExtractor(Extractor):
Expand Down Expand Up @@ -527,12 +528,20 @@ def _call(self, endpoint, params=None):

self.login()
response = self.extractor.request(url, params=params, fatal=False)
data = response.json()

if response.status_code < 400:
return response.json()
if response.status_code == 404:
raise exception.NotFoundError()
raise exception.StopExtraction("API request failed: %s", response.text)
if "error" in data:
if response.status_code == 404:
raise exception.NotFoundError()

error = data["error"]
if "rate limit" in (error.get("message") or "").lower():
self.log.info("Waiting two minutes for API rate limit reset.")
time.sleep(120)
return self._call(endpoint, params)
raise exception.StopExtraction("API request failed: %s", error)

return data

def _pagination(self, endpoint, params, key="illusts"):
while True:
Expand Down

0 comments on commit a27f43d

Please sign in to comment.