Incorrect Context error when calling bpy.ops.view3d.object_as_camera()

I am using blender command line to render image . But before that I need to select active object as camera, which I am doing by calling bpy.ops.view3d.object_as_camera() .
However I am getting the wicked error Operator bpy.ops.view3d.object_as_camera.poll() failed, context is incorrect
Now when I do the following in Python Console in blender , the active camera is selected[‘Camera001-5’].select = True =[‘Camera001-5’][0].camera =[‘Camera001-5’]
for area in bpy.context.screen.areas:
if area.type == ‘VIEW_3D’:
override = bpy.context.copy()
override[‘area’] = area

But when I run the script using blender command line, it gives error again. What to do?

Read here:

poll() failed, context incorrect? - Example: bpy.ops.view3d.background_image_add()

The low-level replacement could be:

scene = bpy.context.scene =['Camera001-5']

for area in bpy.context.screen.areas:
    if area.type == 'VIEW_3D': = 'CAMERA'

I read that post. I think I missed the perspective. Thanks :slight_smile: