gdcc/pyDataverse

SwordApi Authentications fails and get_service_document throws error

Opened this issue · 3 comments

Steps to reproduce:

  • Install latest version of pydataverse
    image

  • Create an instance of SwordApi and try to get the service document

    api = SwordApi("https://demo.dataverse.org/", api_token="give_a_valid_token")
    test1 = api.get_service_document()
  • API fails with the below given error
    Screenshot from 2023-11-15 11-35-14

Additional info:

  • get_request method within ../pyDataverse/api.py sets api_token in params["key"] which is the reason for the error, see the snippet below from the code base
        params = {}
        params["User-Agent"] = "pydataverse"
        if self.api_token:
            params["key"] = str(self.api_token)

        try:
            resp = get(url, params=params)
  • Instead this should be replaced with basic authentication as given below
        params = {}
        params["User-Agent"] = "pydataverse"
        basic = None
        if self.api_token:
            basic = HTTPBasicAuth(self.api_token, '')

        try:
            resp = get(url, params=params, auth=basic)

@skasberger If you could provide me the access, I can also create the pull request immediately, Thanks

@jmurugan-fzj hi! Thanks for your interest in contributing! I'm confused, though. You could create a fork and make your pull request from there, right? Maybe I'm missing something. 🤔

@pdurbin Thanks for the quick response, I have done as suggested and created a PR too: fix(sword-api): get_service_document throws error due to auth-failure, Please take a look and let me know; I am not sure if I can assign any reviewers or change any properties of the PR, just kept it as such!