【问题标题】:FLASK uWSGI NGINX PyPDF2烧瓶 uWSGI NGINX PyPDF2
【发布时间】:2021-05-31 13:00:12
【问题描述】:

我在 ubuntu 18 上的应用程序有问题。

有来自 uWSGI 和 NGINX 的 Flask

下面的错误生成函数

def print_report(year,month):
import pdfkit, os
import app.DB.employee_data as EMP
from PyPDF2 import PdfFileMerger, PdfFileReader
from flask import send_file
emp_list = EMP.emp_list()
output_pdf=PdfFileMerger()
options = {'enable-local-file-access': None}

for emp in emp_list:
    dir_path = os.path.dirname(os.path.realpath(__file__))
    print(dir_path)
    rendered=pracownicy_detail(emp[0],emp[1],year,month)
    pdf = pdfkit.from_string(rendered, 'pdfs/{imie}-{nazwisko}.pdf'.format(imie=emp[0].strip(), nazwisko=emp[1].strip()), options=options)
    output_pdf.append(PdfFileReader('pdfs/{imie}-{nazwisko}.pdf'.format(imie=emp[0].strip(), nazwisko=emp[1].strip()), 'rb'),import_bookmarks=False)
    #usunac pozostale pliki
    os.remove('pdfs/{imie}-{nazwisko}.pdf'.format(imie=emp[0].strip(), nazwisko=emp[1].strip()))
output_pdf.write('pdfs/raport.pdf')

return send_file('../pdfs/raport.pdf', as_attachment=True)

使用 uswgi app.ini 命令手动启动的应用程序 100% 正确运行

作为 app.service 运行会产生“内部服务器错误”

应用程序服务

[Unit]
Description=A simple Flask uWSGI application
After=network.target

[Service]
User=ubuntu-app
Group=www-data
WorkingDirectory=/home/ubuntu-app/app
Environment="PATH=/home/ubuntu-app/app/env/bin"
ExecStart=/home/ubuntu-app/app/env/bin/uwsgi --ini app.ini

[Install]
WantedBy=multi-user.target

NGINX 设置

server {
    listen 80;
    server_name 192.168.2.120;

    location / {
        include uwsgi_params;
        uwsgi_pass unix:/home/ubuntu-app/app/app.sock;
    }
}

app.ini 下面

[uwsgi]
; Production .ini file
module = run:app
master = true

; There is no magic rule for setting the number of processes or threads to use.
; It is very much application and system dependent so you'll need to experiment.
processes = 2
threads = 2



socket = app.sock
chmod-socket = 666
vacuum = true
die-on-term = true

【问题讨论】:

    标签: nginx flask uwsgi pdfkit pypdf2


    【解决方案1】:

    解决方案是添加:

    config = pdfkit.configuration(wkhtmltopdf=bytes('/usr/local/bin/wkhtmltopdf', 'utf-8'))
    

    【讨论】:

      猜你喜欢
      • 2012-11-28
      • 1970-01-01
      • 2017-11-16
      • 2019-09-29
      • 2016-03-20
      • 2015-05-08
      • 2018-02-02
      • 2013-09-01
      • 2013-08-03
      相关资源
      最近更新 更多