Open ChristinaB opened 7 years ago
@ChristinaB
What is a 401 status code error?
It means authentication failed - in this specific case user who is trying to create resource has not provided Hydroshare user account information when using rest client.
We would like to add 'derived from' or to use the new format for adding metadata, did 'derived from' get deprecated?
You can find the supported relation types here (seems we are not supporting 'derived from'): https://github.com/hydroshare/hydroshare/blob/develop/hs_core/models.py#L626
Do you mind giving a bit more direction on how to create a new resource using the REST client?
I think @Castronova should be able to give you some example code for creating a resource. If not I can. How soon you need it?
@ChristinaB
It looks like you may have a few issues here:
createResource
with a HydroShare
instance that has not been authenticated with a username:hsres = hsrc.HydroShare().createResource(rtype, title, abstract=abstract)
This is the same as:
hs = hsrc.HydroShare()
hsres = hs.createResource(rtype, title, abstract=abstract)
As @pkdash pointed out, the unauthenticated user does not have access to create a resources, so what you need to do instead is instantiate the rest client with user credentials (see https://github.com/hydroshare/hs_restclient):
from hs_restclient import HydroShare, HydroShareAuthBasic
auth = HydroShareAuthBasic(username='myusername', password='mypassword')
hs = HydroShare(auth=auth)
hsres = hs.createResource(rtype, title, abstract=abstract)
hs_restclient
and the jupyterhub hydroshare
library (which uses the hs_restclient
)The following is a function defined by the jupyterhub hydroshare
library which is a wrapper around the hs_restlclient.createResource
to provide additional functionality:
resource_id = hs.createHydroShareResource(abstract, title, derivedFromId=None, keywords=keywords, resource_type='genericresource', content_files=files,public=False)
To learn more about this function, issue the following command inside your notebook:
help(hs.createHydroShareResource)
this tells us a little about the createHydroShareResource function
createHydroShareResource(abstract, title, derivedFromId, keywords=[], resource_type='GenericResource', content_files=[], public=False) method of utilities.hydroshare.hydroshare.hydroshare instance
This function takes 3 positional arguments (abstract
, title
, and derivedFromId
) along with several optional parameters.
@pkdash @Castronova Do you mind giving a bit more direction on how to create a new resource using the REST client? We will need to update all of the notebooks, and get other working notebooks going. It would be great to get a functional example beyond what is in the code (is that up to date) ?
Here is the error we get with version 1.2.6 followed by the previous working version. What is a 401 status code error? We also can't find that in the code.
We would like to add 'derived from' or to use the new format for adding metadata, did 'derived from' get deprecated? Thanks!