How to get the name of the property that has a bad driver in Python? I’d like to write a script that will tell me which drivers in a scene have problems. For example, the driver that I’ve highlighted in yellow has problems:



I want to return a list of every driver that has problems, rather than having to look at each driver in a scene individually and determine if it is valid.

Here’s what I have so far:

 import bpy
 for obj in bpy.context.scene.objects: 
     if obj.animation_data:
         if obj.animation_data.drivers:
             for d in obj.animation_data.drivers:
                 if d.driver.is_valid == False:
                     # Now what??


The issue is trying to figure out the name of the property that has the driver. I’ve looked in the API documentation and it’s not immediately obvious how to get that.

In the case of the screenshot above, I want to get (or create) the string value "Y Euler Rotation (forearm.IK.L)".

How do I do that?
Just like keyframes look at data_path and array_index

data_path is the path from the owner of the driver, array index if it is an array type, eg 0, 1, 2 for x, y, z locations. 

Example Y Euler rotation of pose bone "shin.L", from the context object in python console.    

&gt;&gt;&gt; for d in C.object.animation_data.drivers:
...     d.data_path, d.array_index
...     
('pose.bones["shin.L"].rotation_euler', 1)


&gt;&gt;&gt; C.object.pose.bones['shin.L'].rotation_euler[1]
2.0

&gt;&gt;&gt; C.object.pose.bones['shin.L'].rotation_euler.y
2.0


Note for booleans unnecessary to test equality to True/False  ,

if not d.driver.is_valid: