Skip to content

Commit 6fe6c24

Browse files
fix: workaround for requests<2.4.2 missing json parameter
1 parent 93b0cb8 commit 6fe6c24

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

deepl/http_client.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
from typing import Dict, Optional, Tuple, Union
1515
from .util import log_info
1616
from deepl import util
17+
from packaging import version as packaging_version_module
18+
import json as json_module
1719

1820

1921
user_agent = None
@@ -228,8 +230,15 @@ def _prepare_request(
228230
self._app_info_version,
229231
),
230232
)
233+
if packaging_version_module.parse(
234+
requests.__version__
235+
) >= packaging_version_module.parse("2.4.2"):
236+
kwargs["json"] = json
237+
elif json is not None:
238+
data = json_module.dumps(json)
239+
headers["Content-Type"] = "application/json"
231240
return requests.Request(
232-
method, url, data=data, json=json, headers=headers, **kwargs
241+
method, url, data=data, headers=headers, **kwargs
233242
).prepare()
234243
except Exception as e:
235244
raise DeepLException(

0 commit comments

Comments
 (0)