python - 在 Google App Engine 中使用 pdfkit 生成 PDF 会引发 Popen 的 AttributeError

标签 python google-app-engine pdf flask pdfkit

我正在尝试使用 Flask 中的 pdfkit 生成 PDF。 pdfkit 在本地工作正常,但当我在 Google App Engine 中使用它时,会出现以下错误。

Traceback (most recent call last):
  File "C:\Python27\flaskapp\flask\app.py", line 1687, in wsgi_app
    response = self.full_dispatch_request()
  File "C:\Python27\flaskapp\flask\app.py", line 1360, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "C:\Python27\flaskapp\flask\app.py", line 1358, in full_dispatch_request
    rv = self.dispatch_request()
  File "C:\Python27\flaskapp\flask\app.py", line 1344, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "C:\Python27\flaskapp\main.py", line 17, in yout
    pdf = pdfkit.from_string(my_string,False , configuration=config)
  File "C:\Python27\flaskapp\pdfkit\api.py", line 68, in from_string
    return r.to_pdf(output_path)
  File "C:\Python27\flaskapp\pdfkit\pdfkit.py", line 92, in to_pdf
    result = subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE,
AttributeError: 'module' object has no attribute 'Popen'
from flask import Flask, make_response, request, render_template
import pdfkit

path_wkthmltopdf = r'C:\Python27\flaskapp\wkhtmltopdf\bin\wkhtmltopdf.exe'

config = pdfkit.configuration(wkhtmltopdf=path_wkthmltopdf)
app = Flask(__name__)

@app.route('/pdf', methods=['POST', 'GET'])
def pdf():
    if request.method == 'POST':
        my_string = request.form['text11']
        pdf = pdfkit.from_string(my_string, False, configuration=config)

        response = make_response(pdf)
        response.headers['Content-Type'] = 'application/pdf'
        response.headers['Content-Disposition'] = 'inline; filename=out.pdf'

        return response

    return render_template('pdff.html')

最佳答案

此代码无法在 Google App Engine 上运行,因为 App Engine 的 Python runtime environment不允许调用 subprocess.Popen 或启动另一个进程的任何其他调用。

关于python - 在 Google App Engine 中使用 pdfkit 生成 PDF 会引发 Popen 的 AttributeError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40506984/

相关文章:

java - PdfPcell 阿拉伯字符串的空输出

python - 如何在 Python 3.6 中将日期划分为周并创建新列表?

python - S3 响应错误 : 100 Continue - python (appengine)

使用 Objectify 和 Appengine 进行 Spring 事务

javascript - 如何防止 Mobile Safari 在共享时将 PDF 的 base64 编码的 URL 插入到电子邮件中?

python - 用 Python 阅读 PDF 包?

python - Pandas:如何制作双列数据框?

python - 在全息 View 中自定义工具提示

node.js - 从 Node.JS 连接到 Google Cloud SQL 的正确方法

java - 无法使用 DataNucleus GAE/J 插件版本 2 将字节代码增强为 JDO 3.0