【问题标题】:XHTML2PDF Django [Errno 10061] No connection could be made because the target machine actively refused itXHTML2PDF Django [Errno 10061] 无法建立连接,因为目标机器主动拒绝它
【发布时间】:2014-03-04 16:04:44
【问题描述】:

我已经使用 XAMPP 和 mod_wsgi 部署了我的 django 应用程序。在我部署我的应用程序之前一切都很好。但是在我部署之后,pdf dowloand 函数将无法工作并返回错误。

这是我的代码快照

def render_to_pdf(template_src, context_dict, file_name):
    template = get_template(template_src)
    context = Context(context_dict)
    html  = template.render(context)
    result = StringIO.StringIO()
    pdf = pisa.pisaDocument(StringIO.StringIO(html.encode("ISO-8859-1")), result)
    if not pdf.err:
        response = http.HttpResponse(content_type='application/pdf')
        response['Content-Disposition'] = 'attachment; filename="%s"' %(file_name,)
        response.write(result.getvalue())
        return response
    return http.HttpResponse('We had some errors<pre>%s</pre>' % cgi.escape(html))

这是错误

[Errno 10061] No connection could be made because the target machine actively refused it

这是导致错误的代码行

pdf = pisa.pisaDocument(StringIO.StringIO(html.encode("ISO-8859-1")), result)

异常位置:

C:\Python27x32\Lib\socket.py in create_connection, line 571

这是我的 wsgi.py 的代码

<VirtualHost *:80>
    WSGIScriptAlias / "c:/xampp/htdocs/ghb/ghb/wsgi.py"

    <Directory "c:/xampp/htdocs/ghb/">
        <Files wsgi.py>
            Order deny,allow
            Allow from all
        </Files>
    </Directory>

    Alias /static/ C:/xampp/htdocs/ghb/static/

    <Directory c:/xampp/htdocs/ghb/static/>
        Order deny,allow
        Allow from all
    </Directory>
</VirtualHost>

这是Error Log

【问题讨论】:

  • 你能显示完整的回溯吗?
  • 我已经编辑了我的问题

标签: python django


【解决方案1】:

相关的回溯可以在您的error.log 中找到,从第 400 行开始。从这个回溯中,在我看来,您的 HTML 包含一个不起作用的 URL(可能是图像的链接?)指向localhost 并在您的桌面上工作,但不在服务器上?); xhtml2pdf 尝试获取该 URL(可能包括 PDF 中的图像?)但失败了。检查 html 变量(传递给 xhtml2pdf 的 HTML 代码)的内容是否存在损坏的 http:https: 链接。通过跟踪回溯中的文件名+行引用(如File "C:\\Python27x32\\lib\\site-packages\\xhtml2pdf\\parser.py", line 448),您可以更准确地确定 xhtml2pdf 阻塞的元素。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-10-23
    • 1970-01-01
    • 2021-11-10
    • 2012-10-11
    • 2011-10-10
    • 1970-01-01
    • 2013-10-21
    相关资源
    最近更新 更多