تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
2 الردود
1206 أدوات العرض

I'm trying to do import data into odoo (running inside a container) with image url. some of them is webp and whenever odoo try to import those webp it got error :

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/var/lib/odoo/.local/lib/python3.10/site-packages/PIL/Image.py", line 3572, in open
    raise UnidentifiedImageError(msg)
PIL.UnidentifiedImageError: cannot identify image file <_io.BytesIO object at 0x75889b2817b0>

Tried this simple code (like the one used by odoo for importing image with url) :

  • In container python interpreter, it works without error
  • In odoo debugging console, got the error
import io
from PIL import Image
import requests
res = requests.get('https://www.gstatic.com/webp/gallery/1.webp')
content = bytearray()
for chunk in res.iter_content(32768): content += chunk
image = Image.open(io.BytesIO(content))


Odoo tag  :  17.0-20250520

الصورة الرمزية
إهمال

Did you solved the issue? If so, please share.

أفضل إجابة

Why does it work in the container but fail in Odoo?


When you run code in Odoo:


• Odoo may monkey-patch certain libraries (e.g., requests, image handling, base64 encoding).

• Odoo often runs under a different user, environment variables, or restricted execution context than the interactive Python shell.

• The io.BytesIO object or file pointer may be altered (e.g., closed, truncated, or empty) before Image.open() reads it.


Possible causes


Truncated or altered content


• Odoo’s import mechanism may manipulate the content before passing it to Pillow.

• If iter_content or content is re-read multiple times, the BytesIO buffer can be empty.


Pillow plugin mismatch


• The same Pillow version (11.2.1) is reported, but Odoo could be running with disabled or missing WebP plugin if Pillow was compiled differently.

• Some Odoo workers could be using a system-level Pillow without WebP support.


Different error handling for WebP


• Odoo’s image processing pipeline sometimes pre-converts images (e.g., using base64, tools.image_process). This can strip unsupported formats.


Threaded environment or lazy loading


• In multi-threaded environments, race conditions on BytesIO can cause UnidentifiedImageError.


Debugging steps


A. Check the content length inside Odoo


Before Image.open, verify if the buffer has data:


print(len(content))


If 0, the buffer is empty when Odoo executes it.


B. Save the file temporarily to check integrity


with open("/tmp/test.webp", "wb") as f:
f.write(content)


Then manually run Image.open("/tmp/test.webp"). If it opens, Odoo is altering BytesIO.


C. Explicitly load and verify the image


image = Image.open(io.BytesIO(content))
image.load()  # Force full loading
image.verify()


This can help pinpoint lazy loading issues.


D. Check Pillow features at runtime inside Odoo


from PIL import features
print("WebP support:", features.check('webp'))


If this returns False inside Odoo, it’s a plugin issue.


4. Fixes


Option 1: Ensure content is not re-read


When using iter_content, ensure the stream isn’t consumed twice:


res = requests.get(url, stream=True)
content = res.content  # instead of iter_content
image = Image.open(io.BytesIO(content))


Option 2: Upgrade or recompile Pillow with WebP support


Ensure Pillow in the container supports WebP:


apt-get install libwebp-dev
pip install --force-reinstall pillow


Option 3: Use Odoo’s own image tools (avoiding direct Image.open)


Odoo provides tools.image_process which handles WebP gracefully (it may auto-convert to PNG):


from odoo.tools import image_process
image_data = image_process(content)


Option 4: Patch Odoo import code


If Odoo’s import pipeline uses BytesIO incorrectly, add a copy:


buffer = io.BytesIO(content)
buffer.seek(0)
image = Image.open(buffer)


5. Why is it only failing for WebP?


• WebP images are more sensitive to truncation; a small byte mismatch can make Pillow fail.

• Odoo sometimes converts WebP → PNG using an intermediate library, and if this fails silently, you’ll get an empty buffer.


الصورة الرمزية
إهمال
الكاتب أفضل إجابة

Have already tried those. and still same issue.

in debugger attached to container (using debugpy) got error :

In same container but directly in shell (No error) :


It's like if something in odoo is causing the error.

الصورة الرمزية
إهمال

Hello, I am experiencing the same issue. Were you able to resolve it?

الكاتب

No couldn't find any solution until now

المنشورات ذات الصلة الردود أدوات العرض النشاط
1
مارس 25
117
2
مارس 25
1256
1
فبراير 25
1522
1
ديسمبر 24
2025
0
ديسمبر 24
1610