XHTML2PDF Django[Errno 10061]由于目标计算机主动拒绝i

2024-09-30 22:13:00 发布

您现在位置:Python中文网/ 问答频道 /正文

我已经用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))

这是错误

^{pr2}$

下面是导致错误的代码行

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


Tags: pywsgipdfresponse部署html错误context
1条回答
网友
1楼 · 发布于 2024-09-30 22:13:00

相关的回溯可以在第400行开始的error.log中找到。从这个回溯中,我觉得你的HTML包含了一个URL(也许是指向图像的链接?)这不起作用(也许它指向localhost,在桌面上有效,但在服务器上不行?);xhtml2pdf尝试获取该URL(可能是为了在PDF中包含图像?)失败了。检查html变量(传递给xhtml2pdf的HTML代码)中是否存在断开的http:或{}链接。通过跟踪回溯中的filename+行引用(比如File "C:\\Python27x32\\lib\\site-packages\\xhtml2pdf\\parser.py", line 448),可以更精确地确定xhtml2pdf正在阻塞哪个元素。在

相关问题 更多 >