Blender python default function not recognized?
That error indicates that no objects are selected when the operator is run.

The for loop you show should prevent that, so you must have another copy of that (or another) operator call, or you are trying the one line by itself to get the error.