Error uploading (some) python files via API & Storage

Some python files give me this error -

OpenAI API error occurred: Error code: 400 - {‘error’: {‘message’: ‘Invalid file format text/x-objective-c. Supported formats: “c”, “cpp”, “css”, “csv”, “docx”, “gif”, “html”, “java”, “jpeg”, “jpg”, “js”, “json”, “md”, “pdf”, “php”, “png”, “pptx”, “py”, “rb”, “tar”, “tex”, “ts”, “txt”, “webp”, “xlsx”, “xml”, “zip”’, ‘type’: ‘invalid_request_error’, ‘param’: None, ‘code’: None}}
Jun 28 16:27:39 ip-172-31-0-5 web[40252]: 2024-06-28 16:27:39,103 - An error occurred: OpenAI API error: Error code: 400 - {‘error’: {‘message’: ‘Invalid file format text/x-objective-c. Supported formats: “c”, “cpp”, “css”, “csv”, “docx”, “gif”, “html”, “java”, “jpeg”, “jpg”, “js”, “json”, “md”, “pdf”, “php”, “png”, “pptx”, “py”, “rb”, “tar”, “tex”, “ts”, “txt”, “webp”, “xlsx”, “xml”, “zip”’, ‘type’: ‘invalid_request_error’, ‘param’: None, ‘code’: None}}

And others are just fine.

I know that the file upload has been squirly - but wondering if there is a workaround or a fix - I’m certain that the mime type of the file is correct, so it makes me feel like OAI does something to determine file type based on the content and that there might be a simple workaround.

Ideas gratefully accepted :slight_smile:

From the error it seems like you are providing a file with a .m extension (which would match the error ‘t text/x-objective-c’ ? Or possibly a object-c file with the wrong extension (.py)? I would check/upload them one by one to know exacly which one is causing the problem?

1 Like

.m?

The file is called application.py and it’s a python file (mime type text/x-python). Another file with the name Assistants.py (same file type) uploads just fine.

The problem happens both when I use the API and when I use the file upload framework from the Storage section of the dashboard - but only for that file.

Make sure that the file is utf-8 encoded and stored with a valid “.py” extension.

Sometimes, especially on Windows systems, files can have hidden extensions. For example, “code.py” might actually be “code.py.m” (an Objective-C file), with the “.m” hidden.

On Windows, you can check this by enabling “File name extensions” in File Explorer options.

Additionally, you can also add a Python shebang to the first line of that file.

#!/usr/bin/python3
2 Likes