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

Adding NetCDF resource file to a NetcdfResource #96

Open c-krew opened 6 years ago

c-krew commented 6 years ago

I created a composite resource and I am trying to add a netcdf file to the resource. When I do it all in one step, the function works but when I try to do it by creating a resource (hs.createResource) and then adding (hs.addResourceFile) , there is an error. I am adding the resource using a file path but the function thinks its a file-like object and requires a filename.

Here is the code:

hs = HydroShare(auth=auth) abstract = 'Flood Extent App NETCDF for grid ' + str(gridid) title = 'Flood Extent for ' + str(gridid) rtype = 'NetcdfResource' fpath = thredds + "floodedgrid" + str(gridid) + ".nc" # path_to_file resourceid = hs.createResource(rtype, title) response = hs.addResourceFile(resourceid, fpath, resource_filename="flood.nc")

Here is the error:

File "/Users/student/tethys/src/tethys_apps/tethysapp/flood_extent_app/ajax_controllers.py", line 191, in createnetcdf response = hs.addResourceFile(resourceid, fpath, resource_filename="flood.nc") File "/Users/student/tethys/miniconda/envs/tethys/lib/python2.7/site-packages/hs_restclient/init.py", line 859, in addResourceFile raise HydroShareHTTPException((url, 'POST', r.status_code)) File "/Users/student/tethys/miniconda/envs/tethys/lib/python2.7/site-packages/hs_restclient/exceptions.py", line 66, in init self.status_msg = args[3]

pkdash commented 6 years ago

I am guessing the netcdf file may be failing validation. Can you try uploading the same file to a netcdf resource using the website and see if the file gets added to the resource?