【发布时间】:2019-08-24 08:26:19
【问题描述】:
尝试从本地文件系统加载 PDF 并收到“未授权”错误。
“文件”/env/local/lib/python3.7/site-packages/wand/image.py”,第 4896 行,在读取 self.raise_exception() 文件“/env/local/lib/python3.7 /site-packages/wand/resource.py",第 222 行,在 raise_exception 中引发 e wand.exceptions.PolicyError: not authorized `/tmp/tmp_iq12nws' @error/constitute.c/ReadImage/412
PDF 文件已从 GCS 成功保存到本地“服务器”,但不会被 Wand 加载。将图像加载到 OpenCV 中不是问题,只是在尝试使用 Wand/ImageMagick 加载 PDF 时发生
将 PDF 从 GCS 加载到本地文件系统到 Wand/ImageMagick 的代码如下
_, temp_local_filename = tempfile.mkstemp()
gcs_blob = STORAGE_CLIENT.bucket('XXXX').get_blob(results["storedLocation"])
gcs_blob.download_to_filename(temp_local_filename)
# load the pdf into a set of images using imagemagick
with(Image(filename=temp_local_filename, resolution=200)) as source:
#run through pages and save images etc.
ImageMagick 应该被授权访问本地文件系统上的文件,因此它应该毫无问题地加载文件,而不是出现“未授权”错误。
【问题讨论】:
-
这是stackoverflow.com/questions/53296500/…的副本,尚未解决。
-
谢谢 - 经过一番阅读,问题在于 Ghostscript 9.26 版本中的一个安全漏洞,因此 Imagemagick 使用 Ghostscript 读取的所有文件类型都已被禁用。希望 Ghostscript 9.27 中存在安全修复程序,并且 Google Cloud Functions 团队可以快速获取补丁程序。无法手动调整 policy.xml 作为 GCF 环境中的解决方法很糟糕。
-
@kenorb - 不,不能像在 Google Cloud Functions 中那样更改安全设置。
标签: python-3.x pdf imagemagick google-cloud-functions wand