为什么芹菜没有这样的文件或目录错误?



我生成一个PDF并通过电子邮件作为附件发送。每当我运行celery multi start worker -A erp -l info并尝试发送电子邮件时,它都可以工作。但是每当我使用守护程序芹菜执行此操作时,它都会显示以下错误。

[2018-05-11 20:53:47,131: ERROR/ForkPoolWorker-6] Task europarts.tasks.generate_pdf_and_send_email[fd80843b-647c-412e-b847-f35cbf157fae] raised unexpected: OSError(2, 'No such file or directory')
Traceback (most recent call last):
File "/home/michel/erp/venv/lib/python2.7/site-packages/celery/app/trace.py", line 374, in trace_task
R = retval = fun(*args, **kwargs)
File "/home/michel/erp/venv/lib/python2.7/site-packages/celery/app/trace.py", line 629, in __protected_call__
return self.run(*args, **kwargs)
File "europarts/tasks.py", line 58, in generate_pdf_and_send_email
email.attach(file_name, response.rendered_content, 'application/pdf')
File "/home/michel/erp/venv/lib/python2.7/site-packages/wkhtmltopdf/views.py", line 78, in rendered_content
cmd_options=cmd_options
File "/home/michel/erp/venv/lib/python2.7/site-packages/wkhtmltopdf/utils.py", line 186, in render_pdf_from_template
cmd_options=cmd_options)
File "/home/michel/erp/venv/lib/python2.7/site-packages/wkhtmltopdf/utils.py", line 124, in convert_to_pdf
return wkhtmltopdf(pages=filename, **cmd_options)
File "/home/michel/erp/venv/lib/python2.7/site-packages/wkhtmltopdf/utils.py", line 110, in wkhtmltopdf
return check_output(ck_args, **ck_kwargs)
File "/usr/lib64/python2.7/subprocess.py", line 568, in check_output
process = Popen(stdout=PIPE, *popenargs, **kwargs)
File "/usr/lib64/python2.7/subprocess.py", line 711, in __init__
errread, errwrite)
File "/usr/lib64/python2.7/subprocess.py", line 1327, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory

我可以看到在第 58 行,我的函数有错误。但是该功能不会将文件写入磁盘,只是创建PDF并在发送前将其附加到电子邮件中。这是代码:

def generate_pdf_and_send_email(template, filename, context, pk, model, subject, body, from_email, to):
request = RequestFactory().get(reverse('europarts:{model}_email'.format(model=model), args=[pk]))
kw = {
'{model}_id'.format(model=model): pk
}
row_model = '{model}Row'.format(model=model)
rows = apps.get_model('europarts', row_model).objects.filter(**kw)
context['{model}_rows'.format(model=model)] = rows
file_name = '{model}_email.pdf'.format(model=model)
response = PDFTemplateResponse(
request=request,
template=template,
filename=filename,
context=context,
show_content_in_browser=True,
cmd_options={'margin-top': 10,
'zoom': 1,
'viewport-size': '1366 x 513',
'javascript-delay': 1000,
'no-stop-slow-scripts': True},
)
email = EmailMessage()
email.subject = subject
email.body = body
email.from_email = from_email
email.to = to
email.attach(file_name, response.rendered_content, 'application/pdf')
email.send()
return response

我可能做错了什么?

通过找出wkhtmltopdf的安装位置解决了我的问题:

$ which wkhtmltopdf
/usr/local/bin/wkhtmltopdf

并将该位置放在settings.py

WKHTMLTOPDF_CMD = '/usr/local/bin/wkhtmltopdf'

相关内容

  • 没有找到相关文章

最新更新