ERROR ! bpy.ops.render.render.poll() Missing 'window' in context


I’m clearing the objects in the scene after the rendering is finished in the blender, then I repeat my steps to get the rendering again, but the ‘Operator bpy.ops.render.render.poll () Missing’ window ‘in context’ error is getting the render code as follows. After the first rendering, the staged objects are deleted as I want, and then re-drawn. But I get this error when the render command runs. After getting the rendering I thought it might be related to the Image Preview window that pops up. I’ve searched a lot on the internet, but I can’t find a solution. Please help me solve the problem.

its my render code:

scene =['Scene']
scene.render.image_settings.file_format = 'PNG';
global ImgFilePath

ImgFilePath = 'D:\\blenderRenderImage\\' + customerEmail + '_' + id + '.png';

scene.render.filepath = ImgFilePath
bpy.ops.render.render('INVOKE_DEFAULT', write_still=True, use_viewport=True);
return ImgFilePath

Error was:
bpy.ops.render.render.poll() Missing 'window' in context

Debug Error

    Traceback (most recent call last):
  File "C:\Users\PycharmProjects\mobilyaplan\", line 394, in in_40_seconds
  File "C:\Users\PycharmProjects\mobilyaplan\", line 383, in sarginCizimCalistir
    renderAl('[email protected]', '123')
  File "C:\Users\PycharmProjects\mobilyaplan\", line 295, in renderAl
  File "C:\Program Files\Blender Foundation\Blender\2.80\scripts\modules\bpy\", line 199, in __call__
    ret = op_call(self.idname_py(), C_dict, kw, C_exec, C_undo)
RuntimeError: Operator bpy.ops.render.render.poll() Missing 'window' in context

You can see more information -->

you’ll need to create and override the context sent to the operator. It’s not suprising the context is not correct since the main Blender window manager doesn’t even have focus when the error appears