Errno 13尝试运行wkhtmltopdf时权限被拒绝

时间:2017-03-28 19:13:43

标签: django ubuntu nginx wkhtmltopdf

  

有类似的问题,但我的配置不是   我从wkhtmltopdf.org下载了wkhtmltopdf,放在了   项目文件夹,我无法弄清楚为什么我仍然被拒绝访问。

尝试指向django运行wkhtmltopdf以生成pdf文件。

使用UNICORN运行NGINX
使用SUPERVISOR
Ubuntu 16

在我的unicorn_supervisor日志中我得到了:

Internal Server Error: /invoice/1/pdf
    Traceback (most recent call last):emphasized text
      File "/home/instantuser/app/lib/python3.5/site-packages/django/core/handlers/exception.py", line 39, in inner
        response = get_response(request)
      File "/home/instantuser/app/lib/python3.5/site-packages/django/core/handlers/base.py", line 217, in _get_respons                                                                                                                           e
        response = self.process_exception_by_middleware(e, request)
      File "/home/instantuser/app/lib/python3.5/site-packages/django/core/handlers/base.py", line 215, in _get_respons                                                                                                                           e
        response = response.render()
      File "/home/instantuser/app/lib/python3.5/site-packages/django/template/response.py", line 109, in render
        self.content = self.rendered_content
      File "/home/instantuser/app/lib/python3.5/site-packages/wkhtmltopdf/views.py", line 78, in rendered_content
        cmd_options=cmd_options
      File "/home/instantuser/app/lib/python3.5/site-packages/wkhtmltopdf/utils.py", line 186, in render_pdf_from_temp                                                                                                                           late
        cmd_options=cmd_options)
      File "/home/instantuser/app/lib/python3.5/site-packages/wkhtmltopdf/utils.py", line 124, in convert_to_pdf
        return wkhtmltopdf(pages=filename, **cmd_options)
      File "/home/instantuser/app/lib/python3.5/site-packages/wkhtmltopdf/utils.py", line 110, in wkhtmltopdf
        return check_output(ck_args, **ck_kwargs)
      File "/usr/lib/python3.5/subprocess.py", line 626, in check_output
        **kwargs).stdout
      File "/usr/lib/python3.5/subprocess.py", line 693, in run
        with Popen(*popenargs, **kwargs) as process:
      File "/usr/lib/python3.5/subprocess.py", line 947, in __init__
        restore_signals, start_new_session)
      File "/usr/lib/python3.5/subprocess.py", line 1551, in _execute_child
        raise child_exception_type(errno_num, err_msg)
    PermissionError: [Errno 13] Permission denied

wkhtmltopdf文件:

-rwxr-xr-x 1 instantuser instantuser 39804584 Nov 22 10:11 wkhtmltopdf

独角兽进程:

instant+  2949  0.1  0.5  70344 23216 ?        S    18:51   0:00 /home/instantuser/app/bin/python3 ../bin/gunicorn instanthst.wsgi:application --name instanthst --workers 3 --user=instantuser --group=instantuser --bind=unix:/home/instantuser/app/instanthst/run/gunicorn.sock --log-level=debug --log-file=-
instant+  2954  0.3  1.2 171712 51992 ?        S    18:51   0:00 /home/instantuser/app/bin/python3 ../bin/gunicorn instanthst.wsgi:application --name instanthst --workers 3 --user=instantuser --group=instantuser --bind=unix:/home/instantuser/app/instanthst/run/gunicorn.sock --log-level=debug --log-file=-
instant+  2955  0.3  1.2 171704 51936 ?        S    18:51   0:00 /home/instantuser/app/bin/python3 ../bin/gunicorn instanthst.wsgi:application --name instanthst --workers 3 --user=instantuser --group=instantuser --bind=unix:/home/instantuser/app/instanthst/run/gunicorn.sock --log-level=debug --log-file=-
instant+  2957  0.3  1.2 171568 51960 ?        S    18:51   0:00 /home/instantuser/app/bin/python3 ../bin/gunicorn instanthst.wsgi:application --name instanthst --workers 3 --user=instantuser --group=instantuser --bind=unix:/home/instantuser/app/instanthst/run/gunicorn.sock --log-level=debug --log-file=-
ubuntu    2970  0.0  0.0  12944   964 pts/0    S+   18:53   0:00 grep --color=auto unicorn

NGINX流程

root      3006  0.0  0.0 125112  1460 ?        Ss   18:55   0:00 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
www-data  3007  0.0  0.0 125436  3108 ?        S    18:55   0:00 nginx: worker process
www-data  3008  0.0  0.1 125712  5060 ?        S    18:55   0:00 nginx: worker process
ubuntu    3104  0.0  0.0  12944   940 pts/0    S+   19:09   0:00 grep --color=auto nginx

为什么我的访问被拒绝,因为wkhtmltopdf文件所有者是同一个运行的独角兽?

我能够在终端中运行命令,但是python无法运行它。为什么呢?

2 个答案:

答案 0 :(得分:0)

我通过创建一个shell脚本文件来调用wkhtmltopdf来解决这个问题。

<强> wkhtmltopdf.sh

  CREATE VIEW v_customer AS SELECT *,
    CONCAT(lastName, ', ', firstName ) AS wholeName,
   FROM customers; 

谢谢大家的帮助。

答案 1 :(得分:-2)

只需使用     sudo su 要么     sudo命令 这将以超级用户身份运行并绕过所有权限。我是你无法访问超级用户的情况,我不确定。当我试图运行一些不应该运行的东西时,这有时会发生在我身上。虽然我使用的是ubuntu 14.04,所以我不像其他人那样理解这一点。