Page MenuHomePhabricator

byte/str TypeError during svg conversion
Closed, ResolvedPublic

Description

2022-12-14 12:02:12,292 ???? thumbor:ERROR TypeError: write() argument must be str, not bytes

2022-12-14 12:02:12,292 ???? thumbor:ERROR ERROR: Traceback (most recent call last):
  File "/opt/lib/python/site-packages/thumbor/handlers/__init__.py", line 212, in get_image
    result = await self._fetch(self.context.request.image_url)
  File "/opt/lib/python/site-packages/thumbor/handlers/__init__.py", line 876, in _fetch
    raise fetch_result.exception
  File "/opt/lib/python/site-packages/thumbor/handlers/__init__.py", line 844, in _fetch
    self.context.request.engine.load(fetch_result.buffer, extension)
  File "/srv/service/wikimedia_thumbor/engine/proxy/proxy.py", line 125, in load
    self.lcl[enginename].load(buffer, extension)
  File "/opt/lib/python/site-packages/thumbor/engines/__init__.py", line 195, in load
    image_or_frames = self.create_image(buffer)
  File "/srv/service/wikimedia_thumbor/engine/svg/svg.py", line 41, in create_image
    self.prepare_source(buffer)
  File "/srv/service/wikimedia_thumbor/engine/__init__.py", line 56, in prepare_source
    source.write(buffer)
TypeError: write() argument must be str, not bytes

Failing URL: http://staging.svc.eqiad.wmnet:8800/wikipedia/commons/thumb/5/5b/BSicon_exINT-L_grey.svg/800px-BSicon_exINT-L_grey.svg.png

Related Objects

Event Timeline

Change 868456 had a related patch set uploaded (by Vlad.shapik; author: Vlad.shapik):

[operations/software/thumbor-plugins@master] Fix TypeError of SVG conversion

https://gerrit.wikimedia.org/r/868456

It seems that I found where is the trick. As it turned out the failed SVG file has a small body, as a result, the source in the prepare_source function can be created from a buffer and the buffer is a byte string. So it requires opening a file to write bytes.
Other files I took to test this bug have a bigger body, so the source was taken from the context and there is no need to create a temporary file and write to this file in the prepare_source function.

Change 868456 merged by jenkins-bot:

[operations/software/thumbor-plugins@master] Fix TypeError of SVG conversion

https://gerrit.wikimedia.org/r/868456