首页 > 解决方案 > CAIRO_STATUS_WRITE_ERROR:b'error while writing to output stream' on Google Cloud Functions

问题描述

我正在使用cairosvg库,以便使用谷歌云函数将一些 svg 文件转换为 png,但是CAIRO_STATUS_WRITE_ERROR当我在谷歌云函数中运行时出现错误。

svg_string = """
<svg baseProfile="full" height="100%" version="1.1" width="100%"
  xmlns="http://www.w3.org/2000/svg">
  <circle cx="50" cy="50" r="40" />
</svg>
"""
cairosvg.svg2png(
    bytestring=svg_string, write_to='/tmp/output.png')

堆栈跟踪:

Traceback (most recent call last): File
"/env/local/lib/python3.7/site-packages/google/cloud/functions_v1beta2/worker.py", line 281, in run_background_function
_function_handler.invoke_user_function(event_object) File
"/env/local/lib/python3.7/site-packages/google/cloud/functions_v1beta2/worker.py", line 171, in invoke_user_function return call_user_function(request_or_event)
File
"/env/local/lib/python3.7/site-packages/google/cloud/functions_v1beta2/worker.py", line 168, in call_user_function
event_context.Context(**request_or_event.context)) File "/user_code/main.py", line 54, in handle_upload bytestring=svg_string,
write_to='/tmp/output.png') File "/env/local/lib/python3.7/site-packages/cairosvg/__init__.py", line 45,
in <lambda> surface_type.convert(*args, **kwargs))(_surface_type) File
"/env/local/lib/python3.7/site-packages/cairosvg/surface.py", line 139, in convert instance.finish() File
"/env/local/lib/python3.7/site-packages/cairosvg/surface.py", line 463, in finish self.cairo.write_to_png(self.output) File
"/env/local/lib/python3.7/site-packages/cairocffi/surfaces.py", line 653, in write_to_png self._pointer, _encode_filename(target))) File
"/env/local/lib/python3.7/site-packages/cairocffi/__init__.py", line 79, in _check_status raise exception(message, status) OSError: [Errno
cairo returned CAIRO_STATUS_WRITE_ERROR: b'error while writing to output stream'] 11

标签: pythonsvggoogle-cloud-platformgoogle-cloud-functions

解决方案


如果元素上没有属性,该cairosvg包无法呈现具有相对高度或宽度的 SVG 。viewBoxsvg


推荐阅读