Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(sword-api): get_service_document throws error due to auth-failure #163

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions src/pyDataverse/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import subprocess as sp

from requests import ConnectionError, Response, delete, get, post, put
from requests.auth import HTTPBasicAuth

from pyDataverse.exceptions import (
ApiAuthorizationError,
Expand Down Expand Up @@ -112,13 +113,13 @@ def get_request(self, url, params=None, auth=False):
Response object of requests library.

"""
params = {}
params["User-Agent"] = "pydataverse"
params = {"User-Agent": "pydataverse"}
if self.api_token:
params["key"] = str(self.api_token)

params["key"] = self.api_token
try:
resp = get(url, params=params)
resp = get(url,
params=params,
auth=HTTPBasicAuth(self.api_token, '') if self.api_token else None)
if resp.status_code == 401:
error_msg = resp.json()["message"]
raise ApiAuthorizationError(
Expand Down Expand Up @@ -171,7 +172,11 @@ def post_request(self, url, data=None, auth=False, params=None, files=None):
params["key"] = self.api_token

try:
resp = post(url, data=data, params=params, files=files)
resp = post(url,
data=data,
params=params,
files=files,
auth=HTTPBasicAuth(self.api_token, '') if self.api_token else None)
if resp.status_code == 401:
error_msg = resp.json()["message"]
raise ApiAuthorizationError(
Expand Down