Pydap open_url UnicodeDecodeError

Viewed 46
from pydap.client import open_url
from pydap.cas.urs import setup_session

dataset_url = 'http://test.opendap.org/dap/data/nc/coads_climatology.nc'
session = setup_session(username='****', password='****', check_url=dataset_url)
dataset = open_url(dataset_url, session=session)

The above code works fine without error, with following setting:

geopanda version : 0.9.0 pyproj version : 3.1.0 rioxarray version : 0.5.0 xarray version : 0.18.2 shapely : 1.7.1 rasterio : 1.2.6

However, I got the 'UnicodeDecodeError' as shown below while running the following code. The configurations are similar to the webinar here, around 20th min, who ran the similar code and worked fine. My default encoding:

import locale

locale.getpreferredencoding()
 
'UTF-8'

+++++++++ My code ++++++++++

dataset_url = 'https://thredds.daac.ornl.gov/thredds/dodsC/ornldaac/1840/daymet_v4_daily_na_dayl_2009.nc'
session = setup_session(username='****', password='****', check_url=dataset_url)
dataset = open_url(dataset_url, session=session)

++++++++ Error message ++++++++++

---------------------------------------------------------------------------
UnicodeDecodeError                        Traceback (most recent call last)
/tmp/ipykernel_7075/147578581.py in <module>
     14 
     15     # Using pydap's open_url
---> 16     thredds_ds = open_url(granule_dap)
     17 
     18     # Xarray DataSet - opening dataset via remote OPeNDAP

~/bc/lib/python3.8/site-packages/pydap/client.py in open_url(url, application, session, output_grid, timeout)
     64     never retrieve coordinate axes.
     65     """
---> 66     dataset = DAPHandler(url, application, session, output_grid,
     67                          timeout).dataset
     68 

~/bc/lib/python3.8/site-packages/pydap/handlers/dap.py in __init__(self, url, application, session, output_grid, timeout)
     55         if not r.charset:
     56             r.charset = 'ascii'
---> 57         dds = r.text
     58 
     59         dasurl = urlunsplit((scheme, netloc, path + '.das', query, fragment))

~/bc/lib/python3.8/site-packages/webob/response.py in _text__get(self)
    620         decoding = self.charset or self.default_body_encoding
    621         body = self.body
--> 622         return body.decode(decoding, self.unicode_errors)
    623 
    624     def _text__set(self, value):

UnicodeDecodeError: 'ascii' codec can't decode byte 0x8b in position 1: ordinal not in range(128)
0 Answers
Related