从pdf转换为图像时出现Python异常

从pdf转换为图像时出现Python异常,python,pdf,imagemagick,ghostscript,wand,Python,Pdf,Imagemagick,Ghostscript,Wand,在我的 在下面截取的代码中,我尝试使用Python Wand将pdf转换为图像。 在我的本地机器上,代码是有效的 file = request.files['file'] if file.filename == '': app.logger.error('Abort Request: Got Empty File') return api_feedback(2, 500, 'Abort Request, got empty file.') if file and al

在我的

在下面截取的代码中,我尝试使用Python Wand将pdf转换为图像。 在我的本地机器上,代码是有效的

file = request.files['file']
if file.filename == '':
       app.logger.error('Abort Request: Got Empty File')
       return api_feedback(2, 500, 'Abort Request, got empty file.')
if file and allowed_file(file.filename, 'pdf_to_image'):
    app.logger.info('Got allowed file type and got correct image and output')
unique_id = str(uuid.uuid4())
filename = unique_id + '.pdf'
file.save('/tmp/' + filename)
im = Image(filename='/tmp/' + filename, resolution=200)
for i, page in enumerate(im.sequence):
            with Image(page) as page_image:
                page_image.alpha_channel = False
                new_name = '%s-%s.png' % (unique_id, i)
                with StorageFactory.create(output) as storage:
                    output_file = new_name
                    storage.write_to(output_file, page_image)
如果在服务器上运行代码,则会出现以下错误:

 DelegateError: Postscript delegate failed `/tmp/dc53ce20-a14c-47b9-   
 9129-341b051a3676.pdf': No such file or directory @ 
 error/pdf.c/ReadPDFImage/677

`2016-07-05 13:35:17,085 ERROR: Exception on / [POST] [in /opt//venv/local/lib/python2.7/site-packages/flask/app.py:1423]
Traceback (most recent call last):
    return self.view_functions[rule.endpoint](**req.view_args)
    im = Image(filename='/tmp/' + filename, resolution=200)
  File "/opt/venv/local/lib/python2.7/site-packages/wand/image.py", line 2744, in __init__
    self.read(filename=filename, resolution=resolution)
  File "/opt/venv/local/lib/python2.7/site-packages/wand/resource.py", line 222, in raise_exception
    raise e
DelegateError: Postscript delegate failed `/tmp/160cc23f-3842-40dc-a440-3eeee8c6c5fe.pdf': No such file or directory @ error/pdf.c/ReadPDFImage/677
2016-07-05 13:35:17,086 ERROR: Internal Error details: [in ./app/__init__.py:40]
2016-07-05 13:35:17,086 ERROR: Postscript delegate failed `/tmp/160cc23f-3842-40dc-a440-3eeee8c6c5fe.pdf': No such file or directory @ error/pdf.c/ReadPDFImage/677 [in ./app/__init__.py:41] `

Python是否说明错误在哪一行?另外,您是否确定名为
dc53ce20-a14c-47b9-9129-341b051a3676.PDF的PDF文件存在?是,该文件存在。在代码段的第3行中,我将其保存到/tmp目录。使用ls,我可以看到tmp目录中的文件。我在问题where/how is
file
defined中添加了错误?我在问题中添加了代码片段。文件来自post请求。您是否尝试将其保存到与桌面上的tmp不同的目录中?Python是否说明错误在哪一行?另外,您是否确定名为
dc53ce20-a14c-47b9-9129-341b051a3676.PDF的PDF文件存在?是,该文件存在。在代码段的第3行中,我将其保存到/tmp目录。使用ls,我可以看到tmp目录中的文件。我在问题where/how is
file
defined中添加了错误?我在问题中添加了代码片段。文件来自post请求。您是否尝试保存到与tmp不同的目录(如桌面)?