[GIS] gdal.Open error: ‘NoneType’ object has no attribute ‘GetRasterBand’

gdalosgeopython

I am running a python script which calibrates a hydrologic model, this script uses gdal from Osgeo. Following is the command I am giving python:

from osgeo import gdal
infile="G:\ARORA\vic_inputs\routing_files\new_basin\sutlej_beas_new_fraction.tif"
ds = gdal.Open(infile,gdal.GA_ReadOnly)
b1 = ds.GetRasterBand(band)

b1 gives the following error:

AttributeError Traceback (most recent call last)
<ipython-input-33-ba605a73e25c> in <module>()
----> 1 b1 = ds.GetRasterBand(band)

AttributeError: 'NoneType' object has no attribute 'GetRasterBand'

The type(ds) returns NoneType.

What could be wrong here?

Best Answer

I had the same problem. I just capitalised tif in the path. It got solved that way. So try replacing tif as TIF.

Also write the path in r"" so that you don't have to change the \.