From 6a4218aa238d1074904dd39ec553a4df5127ebed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Wed, 6 Dec 2023 21:33:40 +0100 Subject: [PATCH] handle 'json' parameter in Extractor.request() manually Mainly to allow passing custom classes like util.LazyPrompt, but also to simplify and streamline how requests handles it. --- gallery_dl/extractor/common.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/gallery_dl/extractor/common.py b/gallery_dl/extractor/common.py index bf4de4d4..9b010c59 100644 --- a/gallery_dl/extractor/common.py +++ b/gallery_dl/extractor/common.py @@ -136,6 +136,18 @@ class Extractor(): kwargs["timeout"] = self._timeout if "verify" not in kwargs: kwargs["verify"] = self._verify + + if "json" in kwargs: + json = kwargs["json"] + if json is not None: + kwargs["data"] = util.json_dumps(json).encode() + del kwargs["json"] + headers = kwargs.get("headers") + if headers: + headers["Content-Type"] = "application/json" + else: + kwargs["headers"] = {"Content-Type": "application/json"} + response = None tries = 1