2014-03-04 52 views
0

我已经使用XAMPP & mod_wsgi部署了我的django应用程序。在部署我的应用程序之前,一切都很好。但是,我部署它后,PDF dowloand函数将无法正常工作并返回错误。XHTML2PDF Django [Errno 10061]由于目标机器主动拒绝,无法建立连接

这里是我的代码

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

+0

你能展示完整的追溯? –

+0

我编辑了我的问题 –

回答

2

相关回溯可以在你的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正在窒息的元素。

+0

感谢队友,你是我的救星。 –

+0

太棒了,谢谢 –

相关问题