Python Script attribute error while using node editor I am trying to use blender python script for creating textures in cycles render mode. While executing a script which is to be used to get the nodes, I am getting an attribute error

AttributeErrror: 'NoneType' object has no attribute 'nodes'

Here's the code I am using

import bpy
import os

mat = bpy.data.materials["Material"]

nodes = mat.node_tree.nodes
material_output = nodes.get ("Material Output")

node_texture = nodes.new(type='ShaderNodeTexImage')
node_texture.image = bpy.data.images.load ('C:\\Users\\KM\\Desktop\\Blender\\auto.png')
node_texture.projection = "LINEAR"


links = mat.node_tree.links
link = links.new(node_texture.otputs[0], nodes.get("DIffuse BSDF"),inputs[0])


The error is from the line "nodes = mat.node_tree.nodes". Hope you guys can help clear the doubt.

Apologies if the question seems trivial, I am very new to blender and Thanks in advance for your help
probably this material has been created for the blender render engine (by default nodes are disabled ) so you just have to enable using nodes before accessing the node tree by the following line : mat.use_nodes = True then you'll have access to the node tree, you can do a test before accessing to avoid getting into errors