ioos / erddapy

Python interface for ERDDAP
https://ioos.github.io/erddapy/
BSD 3-Clause "New" or "Revised" License
77 stars 30 forks source link

Permission denied when accessing griddap through `.to_xarray()` #301

Closed MathewBiddle closed 1 year ago

MathewBiddle commented 1 year ago

I'm trying to process a bunch of datasets on coastwatch ERDDAP that match a specific query. For most of the datasets, the code below works just fine. However, there are a few datasets (I identified one in the code below) that return a Permission denied error. @ocefpaf mentioned this could have something to do with Windows file locking system... Let me know if you need more info.

Code:

from erddapy import ERDDAP
import pandas as pd

server = "https://coastwatch.pfeg.noaa.gov/erddap/"

protocol = "griddap"

search_for = 'sanctsound "Sound Production"'

e = ERDDAP(server=server, protocol=protocol)

url = e.get_search_url(search_for=search_for, response="csv")

datasets = pd.read_csv(url)[["Dataset ID","Title"]]

e.dataset_id = datasets['Dataset ID'][12] # 'noaaSanctSound_CI01_01_bluewhale'

ds = e.to_xarray()

Error message:

---------------------------------------------------------------------------
PermissionError                           Traceback (most recent call last)
File ~\programs\Miniforge\envs\sandbox\lib\site-packages\erddapy\core\netcdf.py:17, in _nc_dataset(url, requests_kwargs)
     16 try:
---> 17     return Dataset(Path(urlparse(url).path).name, memory=data.read())
     18 except OSError:
     19     # if libnetcdf is not compiled with in-memory support fallback to a local tmp file

File src\netCDF4\_netCDF4.pyx:2463, in netCDF4._netCDF4.Dataset.__init__()

File src\netCDF4\_netCDF4.pyx:2026, in netCDF4._netCDF4._ensure_nc_success()

PermissionError: [Errno 1] Operation not permitted: b'noaaSanctSound_CI01_01_bluewhale.nc'

During handling of the above exception, another exception occurred:

PermissionError                           Traceback (most recent call last)
File <timed exec>:3

File ~\programs\Miniforge\envs\sandbox\lib\site-packages\erddapy\erddapy.py:371, in ERDDAP.to_xarray(self, **kw)
    369 url = self.get_download_url(response=response)
    370 requests_kwargs = {"auth": self.auth}
--> 371 return to_xarray(url, response, requests_kwargs, xarray_kwargs=dict(**kw))

File ~\programs\Miniforge\envs\sandbox\lib\site-packages\erddapy\core\interfaces.py:76, in to_xarray(url, response, requests_kwargs, xarray_kwargs)
     74     return xr.open_dataset(url, **(xarray_kwargs or {}))
     75 else:
---> 76     nc = _nc_dataset(url, requests_kwargs)
     77     return xr.open_dataset(
     78         xr.backends.NetCDF4DataStore(nc), **(xarray_kwargs or {})
     79     )

File ~\programs\Miniforge\envs\sandbox\lib\site-packages\erddapy\core\netcdf.py:22, in _nc_dataset(url, requests_kwargs)
     20 data.seek(0)
     21 with _tempnc(data) as _nc:
---> 22     return Dataset(_nc)

File src\netCDF4\_netCDF4.pyx:2463, in netCDF4._netCDF4.Dataset.__init__()

File src\netCDF4\_netCDF4.pyx:2026, in netCDF4._netCDF4._ensure_nc_success()

PermissionError: [Errno 13] Permission denied: b'C:\\Users\\MATHEW~1.BID\\AppData\\Local\\Temp\\2\\erddapy__qq19g1h.nc'
MathewBiddle commented 1 year ago

Guess I should mention I'm on a Windows system. I think below might be relevant information:

item name
OS Name Microsoft Windows 10 Enterprise
Version 10.0.19044 Build 19044
System Type x64-based PC
Processor Intel(R) Core(TM) i7-8665U CPU @ 1.90GHz, 2112 Mhz, 4 Core(s), 8 Logical Processor(s)
BIOS Version/Date Dell Inc. 1.23.0, 9/12/2022