hydroshare / hs_restclient

Python client for the https://www.hydroshare.org REST API
BSD 3-Clause "New" or "Revised" License
6 stars 8 forks source link

500 when updating metadata #85

Open jsadler2 opened 6 years ago

jsadler2 commented 6 years ago

When I try using the hs.updateResourceMetadata method like this:

from hs_restclient import HydroShare, HydroShareAuthBasic
import json

auth = HydroShareAuthBasic(username=***, password=***)
hs = HydroShare(auth=auth)
resid2 = '34e7ed1986624563a58672efebdd390d'
md = hs.getScienceMetadata(resid2)
j2 = json.dumps(md)
hs.updateScienceMetadata(resid2, metadata=j2)

I get the following:

---------------------------------------------------------------------------
HydroShareHTTPException                   Traceback (most recent call last)
<ipython-input-63-27c22c37a1c2> in <module>()
----> 1 hs.updateScienceMetadata(resid2, metadata=j2)

/home/jeff/anaconda2/lib/python2.7/site-packages/hs_restclient/__init__.pyc in updateScienceMetadata(self, pid, metadata)
    469                 raise HydroShareNotFound((pid,))
    470             else:
--> 471                 raise HydroShareHTTPException((url, 'PUT', r.status_code, metadata))
    472 
    473         return r.json()

HydroShareHTTPException: Received status 500 Internal Server Error when accessing https://www.hydroshare.org/hsapi/resource/34e7ed1986624563a58672efebdd390d/scimeta/elements/ with method PUT and params {"coverages": [], "publisher": null, "dates": [{"type": "modified", "start_date": "2017-07-26T18:29:02.001898Z", "end_date": null}, {"type": "created", "start_date": "2017-07-24T19:12:17.676749Z", "end_date": null}], "funding_agencies": [], "description": "Figures resulting from RF modeling of flood counts", "contributors": [], "title": "RF Flood modeling result figures", "identifiers": [{"url": "http://www.hydroshare.org/resource/34e7ed1986624563a58672efebdd390d", "name": "hydroShareIdentifier"}], "relations": [{"type": "isCreatedBy", "value": "https://www.hydroshare.org/resource/ae53ae6bd4374dd1a292b3555b9fa5f7/"}], "language": "eng", "subjects": [{"value": "Flood Modeling"}, {"value": "Random Forest"}, {"value": "Machine Learning"}], "sources": [{"derived_from": "https://www.hydroshare.org/resource/fd16a9752554486b8928dd75220b8e96/"}], "formats": [{"value": "image/png"}], "rights": "This resource is shared under the Creative Commons Attribution CC BY. http://creativecommons.org/licenses/by/4.0/", "creators": [{"name": "Jeff  Sadler", "order": 1, "phone": "", "address": null, "organization": "University of Virginia", "homepage": null, "email": "jms3fb@virginia.edu", "description": "/user/320/"}], "type": "http://www.hydroshare.org/terms/GenericResource"}.

Am I doing something wrong? (the resource id above is of a public resource so you should be able to replicate this)

jsadler2 commented 6 years ago

@pkdash any ideas on this one?

pkdash commented 6 years ago

@jsadler2 I would expect it to give a 400 error (bad request) in this case since you are trying to update some metadata elements that are not supposed to be updated by the user. For example, date element with type 'created'.