This function is still working fine for me, employing the Python module (1.23.6) to abstract away the HTTP method:
def upload_file():
filename = input("Enter the filename to upload: ")
try:
with open(filename, "rb") as file:
response = client.files.create(file=file, purpose="assistants")
print(response)
print(f"File uploaded successfully: {response.filename} [{response.id}]")
except FileNotFoundError:
print("File not found. Please make sure the filename and path are correct.")
The code you show also doesnāt set the file ID from the response, so it could not have been working as intended before.
I donāt think the āpurposeā should matter (It might have other implications but to test file upload it shouldnāt matter).
I uploaded a PDF file with āfine-tuneā as purpose and it worked as expected.
Looking at the error it appears to be an issue with how the request headers are configured. Are you explicitly configuring the header somewhere else in your code?