Skip to content

Commit 929e5c9

Browse files
committed
pass data as json to request method
1 parent e149282 commit 929e5c9

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

pyDataverse/api.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -167,19 +167,22 @@ def post_request(self, url, data=None, auth=False, params=None, files=None):
167167
if self.api_token:
168168
params["key"] = self.api_token
169169

170+
if isinstance(data, str):
171+
data = json.loads(data)
172+
170173
if self.client is None:
171174
return self._sync_request(
172175
method=httpx.post,
173176
url=url,
174-
data=data,
177+
json=data,
175178
params=params,
176179
files=files,
177180
)
178181
else:
179182
return self._async_request(
180183
method=self.client.post,
181184
url=url,
182-
data=data,
185+
json=data,
183186
params=params,
184187
files=files,
185188
)
@@ -210,18 +213,21 @@ def put_request(self, url, data=None, auth=False, params=None):
210213
if self.api_token:
211214
params["key"] = self.api_token
212215

216+
if isinstance(data, str):
217+
data = json.loads(data)
218+
213219
if self.client is None:
214220
return self._sync_request(
215221
method=httpx.put,
216222
url=url,
217-
data=data,
223+
json=data,
218224
params=params,
219225
)
220226
else:
221227
return self._async_request(
222228
method=self.client.put,
223229
url=url,
224-
data=data,
230+
json=data,
225231
params=params,
226232
)
227233

@@ -287,7 +293,6 @@ def _sync_request(
287293

288294
try:
289295
resp = method(**kwargs, follow_redirects=True)
290-
291296
if resp.status_code == 401:
292297
error_msg = resp.json()["message"]
293298
raise ApiAuthorizationError(

0 commit comments

Comments
 (0)