MCPcopy
hub / github.com/mikf/gallery-dl / request

Method request

gallery_dl/extractor/common.py:147–265  ·  view source on GitHub ↗
(self, url, method="GET", session=None, fatal=True,
                retries=None, retry_codes=None, expected=(), interval=True,
                encoding=None, notfound=None, **kwargs)

Source from the content-addressed store, hash-verified

145 return values
146
147 def request(self, url, method="GET", session=None, fatal=True,
148 retries=None, retry_codes=None, expected=(), interval=True,
149 encoding=None, notfound=None, **kwargs):
150 if session is None:
151 session = self.session
152 if retries is None:
153 retries = self._retries
154 if retry_codes is None:
155 retry_codes = self._retry_codes
156 if "proxies" not in kwargs:
157 kwargs["proxies"] = self._proxies
158 if "timeout" not in kwargs:
159 kwargs["timeout"] = self._timeout
160 if "verify" not in kwargs:
161 kwargs["verify"] = self._verify
162
163 if "json" in kwargs:
164 if (json := kwargs["json"]) is not None:
165 kwargs["data"] = util.json_dumps(json).encode()
166 del kwargs["json"]
167 if headers := kwargs.get("headers"):
168 headers["Content-Type"] = "application/json"
169 else:
170 kwargs["headers"] = {"Content-Type": "application/json"}
171
172 response = challenge = None
173 tries = 1
174
175 if self._interval_request is not None and interval:
176 seconds = (self._interval_request() -
177 (time.time() - Extractor.request_timestamp))
178 if seconds > 0.0:
179 self.sleep(seconds, "request")
180
181 while True:
182 try:
183 response = session.request(method, url, **kwargs)
184 except requests.exceptions.ConnectionError as exc:
185 try:
186 reason = exc.args[0].reason
187 cls = reason.__class__.__name__
188 pre, _, err = str(reason.args[-1]).partition(":")
189 msg = f" {cls}: {(err or pre).lstrip()}"
190 except Exception:
191 msg = exc
192 code = 0
193 except (requests.exceptions.Timeout,
194 requests.exceptions.ChunkedEncodingError,
195 requests.exceptions.ContentDecodingError) as exc:
196 msg = exc
197 code = 0
198 except (requests.exceptions.RequestException) as exc:
199 msg = exc
200 break
201 else:
202 code = response.status_code
203 if self._write_pages:
204 self._dump_response(response)

Callers 15

request_locationMethod · 0.95
request_jsonMethod · 0.95
request_xmlMethod · 0.95
_download_implMethod · 0.45
itemsMethod · 0.45
itemsMethod · 0.45
fetch_albumMethod · 0.45
_manga_infoMethod · 0.45
itemsMethod · 0.45
_paginationMethod · 0.45
imagesMethod · 0.45
imagesMethod · 0.45

Calls 7

sleepMethod · 0.95
_dump_responseMethod · 0.95
waitMethod · 0.95
getMethod · 0.80
_handle_429Method · 0.80
warningMethod · 0.45
debugMethod · 0.45

Tested by

no test coverage detected