"bpy.ops.rigidbody.world_add.poll() failed, context is incorrect" occurs when python script is ran more than once
When you first start Blender there is no rigid body world added to the context. You can check this by running print(C.scene.rigidbody_world) in the console. This should return None
When you run bpy.ops.rigidbody.world_add() you are adding a new rigid body world to bpy.context.scene If you now enter print(C.scene.rigidbody_world) you should get something like &lt;bpy_struct, RigidBodyWorld at 0x00000225720128B8&gt;
If you immediately run bpy.ops.rigidbody.world_add() again the error you get should be something like RuntimeError: Operator bpy.ops.rigidbody.world_add.poll() failed, context is incorrect This tells us that the operator's poll() method is checking &quot;something&quot; in the context and since we know that what has changed is that we now have a rigidbody_world in our context, we can assume that this is what the poll function is checking for. (actually checking this is a bit of a pain as it means tracking down the operator)
Wrapping up - you have two options.

remove the rigidbody world using bpy.ops.rigidbody.world_remove() before rerunning your script
Check if there is already a rigidbody world added before adding one and skipping if there is.