2014-03-04 56 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

太棒了,謝謝 –

相關問題