context.material.node_tree - context has no attribute to material?
Different contexts also can have different context members. 


  Context Access (bpy.context)
  
  The context members available depend on the area of Blender which is
  currently being accessed.


The properties panel is a classic example.  Looking at property panel code may come across context.material or context.modifier but will find them unavailable in say the python console. 

&gt;&gt;&gt; C.material
Traceback (most recent call last):
  File "&lt;blender_console&gt;", line 1, in &lt;module&gt;
AttributeError: 'Context' object has no attribute 'material'


Use another way to get material, from the active object

&gt;&gt;&gt; C.object.active_material
bpy.data.materials['Material']


Re creating a material

Add Nodes to Material with Python

Python: Add existing NodeGroup to Material