WebP files not recognized by mimetypes.guess_type() in Python <3.13 #425
Labels
component:python sdk
Issue/PR related to Python SDK
type:feature request
New feature request/enhancement
Description of the bug:
When attempting to use a WebP image with the generate_content() function of the Gemini API, an "Unsupported MIME type" error is encountered. This occurs despite WebP being a widely supported image format.
Environment:
Code to reproduce:
Error Message:
Actual vs expected behavior:
Actual behavior:
The API returns a 400 BadRequest error with the message "Unsupported MIME type: application/octet-stream" when attempting to process a WebP image.
Expected behavior:
The API should recognize and process the WebP image format, allowing for text generation as it does with other supported image formats like JPEG or PNG.
Any other information you'd like to share?
Problem Description
The Gemini API is throwing an "Unsupported MIME type" error when attempting to process WebP images. This issue likely stems from the upload_file function:
generative-ai-python/google/generativeai/files.py
Lines 60 to 61 in 45fcbdf
Current Workaround
Users can explicitly specify the MIME type when calling upload_file:
Broader Context
This issue is likely to affect other users who don't specify the MIME type explicitly.
Python 3.13 will include a fix for this in the core mimetypes module (see python/cpython#111741). Users on Python 3.13+ won't encounter this error.
For users on Python versions lower than 3.13, a potential solution would be to add the WebP MIME type manually:
Suggested Improvements
Update the library to include the manual addition of the WebP MIME type:
mimetypes.add_type('image/webp', '.webp')
This would ensure compatibility across all Python versions.
Consider updating the upload_file function to handle WebP files explicitly, even if
mimetypes.guess_type
fails.The text was updated successfully, but these errors were encountered: