【问题标题】:CAIRO_STATUS_WRITE_ERROR: b'error while writing to output stream' on Google Cloud FunctionsCAIRO_STATUS_WRITE_ERROR:b'error while writing to output stream' on Google Cloud Functions
【发布时间】:2018-09-10 21:41:35
【问题描述】:

我正在使用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

【问题讨论】:

  • 如果在svg 元素中添加viewBox,错误是否仍然存在?
  • @Dustin 完美无瑕,谢谢!

标签: python svg google-cloud-platform google-cloud-functions


【解决方案1】:

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

【讨论】:

猜你喜欢
  • 2021-04-27
  • 2016-07-20
  • 1970-01-01
  • 2018-10-01
  • 2020-09-27
  • 1970-01-01
  • 1970-01-01
  • 2022-12-26
  • 2019-06-12
相关资源
最近更新 更多