From 9a7aa68a3e2b3228e4fb24532f90450f4c3f12bf Mon Sep 17 00:00:00 2001 From: Alex Novaes de Santana Date: Thu, 7 Apr 2022 11:22:43 +0200 Subject: [PATCH] Accessing the Exception message via e.args[0] When opening gz files, in the case of the TypeError exception, another exception would be raised: AttributeError: 'TypeError' object has no attribute 'message' As python 3 exceptions have no attribute message, I replace it for e.args[0] following the pattern a few lines below. --- xarray/backends/scipy_.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/xarray/backends/scipy_.py b/xarray/backends/scipy_.py index 4c1ce1ef09d..df3ee364546 100644 --- a/xarray/backends/scipy_.py +++ b/xarray/backends/scipy_.py @@ -86,7 +86,8 @@ def _open_scipy_netcdf(filename, mode, mmap, version): ) except TypeError as e: # TODO: gzipped loading only works with NetCDF3 files. - if "is not a valid NetCDF 3 file" in e.message: + errmsg = e.args[0] + if "is not a valid NetCDF 3 file" in errmsg: raise ValueError("gzipped file loading only supports NetCDF 3 files.") else: raise