Python script implementation throws an error on a specific syntax

I’m trying to run a Python script in Unreal Engine, but I keep getting errors with certain syntax. The error log looks like this
‘’’
LogPython: Error: with safe_open(checkpoint_file, framework=“pt”) as f:
‘’’

The Python code is
‘’’
with safe_open(r"D:\unreal_project\PlayfabMenu_retire_3\Content\chatbot\model.safetensors", framework=“pt”) as f:
metadata = f.metadata()
‘’’

This is the same as above, but if you replace this code with the following, it will work.
‘’’
f=safe_open(checkpoint_file, framework=“pt”)
‘’’

But when used with the ‘with’ statement, it’s throwing an error. Everything else seems to be working fine, so why does it throw an error when I run it with the with statement?