dataverse-client-python
dataverse-client-python copied to clipboard
Allow username and password to be passed to Connection object
... as an alternative to the API token. I can try and open a pull request if you like.
As far as I know, support has been dropped for username/password authentication in favor of API tokens in Dataverse 4.0 (see http://guides.dataverse.org/en/latest/api/sword.html#backward-incompatible-changes). The client in its current state is very 3.X incompatible, but I could point you to the last 3.6 compatible commit that still accepted usernames/passwords if you are trying to work with an older installation.
Actually I was referring more to the new native API which allows one to get the API token from the username and password. This could happen seamlessly inside the Connection object, right? In my mini-Python library I do:
LOGIN_URL = "https://{server}/api/builtin-users/{username}/api-token?password={password}"
class Connection(object):
def __init__(self, username=None, password=None, api_token=None, server=None):
self.server = server
self.username = username
if username is not None:
if password is None:
raise ValueError("password is not set")
url = LOGIN_URL.format(server=server, username=username, password=password)
response = requests.get(url).json()
self.api_token = parse_response(response)['message']
else:
self.api_token = api_token
Yeah, that works.
The only issue that could come up is that currently, you have to generate the API token through the GUI before you can retrieve it through the API, but with good error handling that shouldn't be a problem. If this is something you would use, feel free to open a PR.
currently, you have to generate the API token through the GUI before you can retrieve it through the API
Right. See also https://github.com/IQSS/dataverse/issues/1935