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

Hello,

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 = bpy.data.scenes['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\__init__.py", line 394, in in_40_seconds
    sarginCizimCalistir()
  File "C:\Users\PycharmProjects\mobilyaplan\__init__.py", line 383, in sarginCizimCalistir
    renderAl('[email protected]', '123')
  File "C:\Users\PycharmProjects\mobilyaplan\__init__.py", line 295, in renderAl
    bpy.ops.render.render('INVOKE_DEFAULT');
  File "C:\Program Files\Blender Foundation\Blender\2.80\scripts\modules\bpy\ops.py", 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 --> https://prnt.sc/qj8upb https://www.loom.com/share/885a83c821f54f68945ba514f753d70a

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