python - 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
解决方案
如果元素上没有属性,该cairosvg
包无法呈现具有相对高度或宽度的 SVG 。viewBox
svg
推荐阅读
- firebase - .apns 文件中的数据格式,用于在 iOS 模拟器中测试 Firebase 通知
- python - PYTHON:使用附魔库识别 Pandas 数据框中的非英语单词
- batch-file - 在 Windows 批处理文件中使用 ImageMagick 批处理图像
- highcharts - Highcharts 组织改变大小图像和位置
- python - 有没有办法让我的不和谐机器人一次与一个人一起使用?
- javascript - Angular - 在子组件中重新加载或刷新对象
- python-3.x - python升级后使用ubuntu终端的问题
- ms-word - Windows 10 Word 365 文件名时间戳自动化 w/o VBA
- javascript - html中的样式字体css无法正常工作
- java - 如何修复 TicTacToe 方法的索引 9 超出长度 9 的范围