fix(sword-api): get_service_document throws error due to auth-failure
- 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
- [x] OS: Linux, Ubuntu 22.04.1, 64bit
- [x] pyDataverse: 0.3.1
- [x] Python: 3.10.12
- [x] Dataverse: v. 6.0 build 1512-366fd41
Follow best practices
- [x] Have you checked to ensure there aren't other open Pull Requests for the same update/change?
- [x] Have you followed the guidelines in our Contribution Guide?
- [x] Have you read the Code of Conduct?
- [x] 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_NUMBERto 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
- [x] Have descriptive commit messages with a short title (first line).
- [x] Use the commit message template
- [x] Put
Closes #ISSUE_NUMBERin 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
@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:
- https://github.com/gdcc/dataverse-action/issues/6
@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?
Yes, it would be great to talk. Maybe next week? I'm hoping to know more about the pyDataverse situation on Monday.
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
@jmurugan-fzj are you on Zulip? @JR-1991 and I talk in #python there. We just advertised this in the README:
- #165
You're very welcome to join us! Maybe there we could figure out a meeting time.
@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!
@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"}}'
Kudos, SonarCloud Quality Gate passed! 
0 Bugs
0 Vulnerabilities
0 Security Hotspots
0 Code Smells
No Coverage information
0.0% Duplication