Python - Trouble when changing context (the first time)
To delete the nodes you should override the context of operator bpy.ops.node.select_all. 
And the reason of error you see is mentioned here.

Actually to delete the nodes, instead of using operator I would use next piece of code:

for node in mat.node_tree.nodes:
    mat.node_tree.nodes.remove(node)

updated with your part:

import bpy

mat = bpy.data.materials.get("Material")
geom = bpy.context.active_object

if mat is None:
    # create material
    mat = bpy.data.materials.new(name="Material")
# Assign it to object
if geom.data.materials:
    # assign to 1st material slot
    geom.data.materials[0] = mat
else:
    # no slots
    geom.data.materials.append(mat)

# delete nodes
for node in mat.node_tree.nodes:
    mat.node_tree.nodes.remove(node)