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
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?


2 Answers 2


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 \. See the documentation: String and Bytes literals


First of all, be sure that your file exists by using:

import os
if not os.path.isfile(infile):
   raise FileNotFoundError(f"Non existing {infile}")

This way, you will directly see if your file is found or not, and if there is a problem with your string.

I agree, on Windows, always use raw strings ( r"") to be sure your \ will be used as separator. However, I don't understand the capitalized TIF part, you must use the syntax your file has!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.