Retrieve file content format error

When AI generates internal sandbox files in formats such as docx and excel, the data returned by the files.retrieve_content(file_id) API is stored in the file, but cannot be read.the code is
content=clients.files.retrieve_content(file_id)
with open(“aa.docx”, “wb”) as f:
f.write(content)