pyDataverse icon indicating copy to clipboard operation
pyDataverse copied to clipboard

SwordApi Authentications fails and get_service_document throws error

Open jmurugan-fzj opened this issue 2 years ago • 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)

jmurugan-fzj avatar Nov 15 '23 13:11 jmurugan-fzj

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

jmurugan-fzj avatar Nov 15 '23 14:11 jmurugan-fzj

@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 avatar Nov 15 '23 16:11 pdurbin

@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!

jmurugan-fzj avatar Nov 17 '23 11:11 jmurugan-fzj