Skip to content

Commit

Permalink
pass data as json to request method
Browse files Browse the repository at this point in the history
  • Loading branch information
JR-1991 committed May 10, 2024
1 parent e149282 commit 929e5c9
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions pyDataverse/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,19 +167,22 @@ def post_request(self, url, data=None, auth=False, params=None, files=None):
if self.api_token:
params["key"] = self.api_token

if isinstance(data, str):
data = json.loads(data)

if self.client is None:
return self._sync_request(
method=httpx.post,
url=url,
data=data,
json=data,
params=params,
files=files,
)
else:
return self._async_request(
method=self.client.post,
url=url,
data=data,
json=data,
params=params,
files=files,
)
Expand Down Expand Up @@ -210,18 +213,21 @@ def put_request(self, url, data=None, auth=False, params=None):
if self.api_token:
params["key"] = self.api_token

if isinstance(data, str):
data = json.loads(data)

if self.client is None:
return self._sync_request(
method=httpx.put,
url=url,
data=data,
json=data,
params=params,
)
else:
return self._async_request(
method=self.client.put,
url=url,
data=data,
json=data,
params=params,
)

Expand Down Expand Up @@ -287,7 +293,6 @@ def _sync_request(

try:
resp = method(**kwargs, follow_redirects=True)

if resp.status_code == 401:
error_msg = resp.json()["message"]
raise ApiAuthorizationError(
Expand Down

0 comments on commit 929e5c9

Please sign in to comment.