我正在尝试使用 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/