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

Conversation

jmurugan-fzj
Copy link

@jmurugan-fzj jmurugan-fzj commented Nov 17, 2023

  • Added logic to set HTTPBasicAuth using api-token for get and post requests which allows the retrieval of service-document without any authentication failures.

Describe your environment

  • OS: Linux, Ubuntu 22.04.1, 64bit
  • pyDataverse: 0.3.1
  • Python: 3.10.12
  • Dataverse: v. 6.0 build 1512-366fd41

Follow best practices

  • Have you checked to ensure there aren't other open Pull Requests for the same update/change?
  • Have you followed the guidelines in our Contribution Guide?
  • Have you read the Code of Conduct?
  • Do your changes in a separate branch. Branches MUST have descriptive names.
  • Have you merged the latest changes from upstream to your branch?

Describe the PR

  • What kind of change does this PR introduce?
    • TEXT
  • Why is this change required? What problem does it solve?
    • TEXT
  • Screenshots (if appropriate)
  • Put Closes #ISSUE_NUMBER to the end of this pull request

Testing

  • Have you used tox and/or pytest for testing the changes?
  • Did the local testing ran successfully?
  • Did the Continous Integration testing (Travis-CI) ran successfully?

Commits

  • Have descriptive commit messages with a short title (first line).
  • Use the commit message template
  • Put Closes #ISSUE_NUMBER in your commit messages to auto-close the issue that it fixes (if such).

Others

  • Is there anything you need from someone else?

Documentation contribution

  • Have you followed NumPy Docstring standard?

Code contribution

  • Have you used pre-commit?
  • Have you formatted your code with black prior to submission (e. g. via pre-commit)?
  • Have you written new tests for your changes?
  • Have you ran mypy on your changes successfully?
  • Have you documented your update (Docstrings and/or Docs)?
  • Do your changes require additional changes to the documentation?

Closes #162

@pdurbin
Copy link
Member

pdurbin commented Nov 17, 2023

@jmurugan-fzj thanks for the pull request!

I wish we had some CI set up to test pyDataverse regularly. That way we could include in pull requests like this some tests asserting that the service document can be retrieved. Would you be interested in helping with this effort? We're spinning up Dataverse in GitHub Actions over at https://github.com/gdcc/api-test-runner and plan to someday create a proper GitHub Action: https://github.com/gdcc/dataverse-action

I just opened this related issue:

@jmurugan-fzj
Copy link
Author

@jmurugan-fzj thanks for the pull request!

I wish we had some CI set up to test pyDataverse regularly. That way we could include in pull requests like this some tests asserting that the service document can be retrieved. Would you be interested in helping with this effort? We're spinning up Dataverse in GitHub Actions over at https://github.com/gdcc/api-test-runner and plan to someday create a proper GitHub Action: https://github.com/gdcc/dataverse-action

I just opened this related issue:

@pdurbin yes sure, I can also support but may not be able to guarantee the priority for this task presently with my work related engagements, may be we could discuss further your expectations regarding my contributions?

@pdurbin
Copy link
Member

pdurbin commented Nov 22, 2023

Yes, it would be great to talk. Maybe next week? I'm hoping to know more about the pyDataverse situation on Monday.

@jmurugan-fzj
Copy link
Author

Yes, it would be great to talk. Maybe next week? I'm hoping to know more about the pyDataverse situation on Monday.

@pdurbin Sure, could you please send me an invite for next week? I am available most days after Monday and my time zone is GMT+1

@pdurbin
Copy link
Member

pdurbin commented Nov 29, 2023

@jmurugan-fzj are you on Zulip? @JR-1991 and I talk in #python there. We just advertised this in the README:

You're very welcome to join us! Maybe there we could figure out a meeting time.

@jmurugan-fzj
Copy link
Author

@jmurugan-fzj are you on Zulip? @JR-1991 and I talk in #python there. We just advertised this in the README:

You're very welcome to join us! Maybe there we could figure out a meeting time.

@pdurbin Thanks, I joined and messaged you there, let me know your availability!

@JR-1991
Copy link
Member

JR-1991 commented Dec 1, 2023

@jmurugan-fzj thanks for the submission! I tested your PR to POST data to Demo Dataverse (using native PyDataverse and EasyDataverse). Everything works fine! Please find the code I have used in the following:

from easyDataverse import Dataverse

# Connect to a Dataverse installation
dataverse = Dataverse(
  server_url="https://demo.dataverse.org",
  api_token="...",
)

# Intiialize a dataset
dataset = dataverse.create_dataset()

# Fill metadata blocks
dataset.citation.title = "My dataset"
dataset.citation.subject = ["Other"]
dataset.citation.add_author(name="John Doe")
dataset.citation.add_dataset_contact(name="John Doe", email="[email protected]")
dataset.citation.add_ds_description(value="This is a description of the dataset")

dataset.upload("ed_test")

response = dataverse.native_api.create_dataset(
    "ed_test",
    dataset.dataverse_json(),
)

print(response.text)

Out

Connecting to https://demo.dataverse.org/
Connection successfuly established!

- Using EasyDataverse

Dataset with pid 'doi:10.70122/FK2/P94QEH' created.
https://demo.dataverse.org/dataset.xhtml?persistentId=doi:10.70122/FK2/P94QEH

- Using native API

Dataset with pid 'doi:10.70122/FK2/PPMKBO' created.
'{"status":"OK","data":{"id":2110496,"persistentId":"doi:10.70122/FK2/PPMKBO"}}'

image

Copy link

sonarqubecloud bot commented Dec 4, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SwordApi Authentications fails and get_service_document throws error
3 participants