简体   繁体   English

CAIRO_STATUS_WRITE_ERROR:在Google Cloud Functions上写入输出流时发生错误

[英]CAIRO_STATUS_WRITE_ERROR: b'error while writing to output stream' on Google Cloud Functions

I'm using the cairosvg library in order to convert some svg files into png using google cloud functions, however I got the error CAIRO_STATUS_WRITE_ERROR when I run inside a google cloud function. 我正在使用cairosvg库,以便使用谷歌云功能将一些svg文件转换为png,但是当我在google云功能中运行时,我收到错误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')

Stacktrace: 堆栈跟踪:

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属性, cairosvg包无法呈现具有相对高度或宽度的svg

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM