@@ -49,6 +49,7 @@ def _set_max_rate_limit(self) -> None:
4949 if self .api_key :
5050 raise NotImplementedError ("I don't know what the rate limit is for calls with an API key is yet." )
5151
52+
5253@dataclass
5354class BaseClient (ABC ):
5455 """
@@ -61,11 +62,20 @@ class BaseClient(ABC):
6162 If True, will throttle the amount of requests per second to the OpenSea API.
6263 If you pass an API key into the client_params instance, the rate limiting will change accordingly.
6364 If False, will not throttle.
65+
66+ retry: bool
67+ OpenSea will occasionally return an empty response object, although the same query would yield
68+ a full response object afterwards.
69+ If True, will pause the request for one second before trying again once.
70+ If it fails again, the empty response is returned.
71+ If set to False, the client always returns the first response object, even if it is empty.
72+
6473 """
6574
6675 client_params : ClientParams
6776 url = None
6877 rate_limiting : bool = True
78+ retry : bool = True
6979
7080 def __post_init__ (self ):
7181 self .processed_pages : int = 0
@@ -103,11 +113,17 @@ def get_pages(self) -> Generator[list[list[BaseResponse]], None, None]:
103113
104114 while self .remaining_pages ():
105115 self ._http_response = self ._get_request ()
116+ self .check_if_response_is_valid ()
106117 if self .parsed_http_response is not None : # edge case
107118 self .processed_pages += 1
108119 self .client_params .offset += self .client_params .page_size
109120 yield self .parsed_http_response
110121
122+ def check_if_response_is_valid (self ):
123+ if not self ._http_response .ok :
124+ logger .warning (f'Page { self .processed_pages } returned a { self ._http_response .status_code } status code: { self ._http_response .reason } \n '
125+ f'{ self ._http_response .text } ' )
126+
111127 def remaining_pages (self ) -> bool :
112128 if self ._http_response is None :
113129 return True
0 commit comments