2016-02-12 127 views
0

我使用django-wkhtmltopdf在我的webapp中生成pdf,使用django集成服務器工作正常,但是當我使用IIS 7.5或8時,出現此錯誤: WindowsError [錯誤6句柄無效如何在IIS 7.5上使用django-wkhtmltopdf生成pdf文件 - 8

環境:

Request Method: GET 
Request URL: http://127.0.0.1:8006/blabla/pdf/10/ 

Django Version: 1.8.5 
Python Version: 2.7.10 
Installed Applications: 
('django.contrib.auth', 
'django.contrib.contenttypes', 
'django.contrib.sessions', 
'django.contrib.sites', 
'django.contrib.messages', 
'django.contrib.staticfiles', 
'django.contrib.admin', 
'django.contrib.admindocs', 
'NuevoTicket', 
'crispy_forms', 
'wkhtmltopdf', 
'ckeditor', 
'ckeditor_uploader') 
Installed Middleware: 
('django.middleware.common.CommonMiddleware', 
'django.contrib.sessions.middleware.SessionMiddleware', 
'django.middleware.csrf.CsrfViewMiddleware', 
'django.contrib.auth.middleware.AuthenticationMiddleware', 
'django.contrib.messages.middleware.MessageMiddleware') 


Traceback: 
File "C:\Python27\lib\site-packages\django\core\handlers\base.py" in get_response 
    164.     response = response.render() 
File "C:\Python27\lib\site-packages\django\template\response.py" in render 
    158.    self.content = self.rendered_content 
File "C:\Python27\lib\site-packages\wkhtmltopdf\views.py" in rendered_content 
    78.    cmd_options=cmd_options 
File "C:\Python27\lib\site-packages\wkhtmltopdf\utils.py" in render_pdf_from_template 
    159.        cmd_options=cmd_options) 
File "C:\Python27\lib\site-packages\wkhtmltopdf\utils.py" in convert_to_pdf 
    121.  return wkhtmltopdf(pages=[filename], **cmd_options) 
File "C:\Python27\lib\site-packages\wkhtmltopdf\utils.py" in wkhtmltopdf 
    109.  return check_output(ck_args, **ck_kwargs) 
File "C:\Python27\lib\subprocess.py" in check_output 
    566.  process = Popen(stdout=PIPE, *popenargs, **kwargs) 
File "C:\Python27\lib\subprocess.py" in __init__ 
    702.   errread, errwrite), to_close = self._get_handles(stdin, stdout, stderr) 
File "C:\Python27\lib\subprocess.py" in _get_handles 
    857.     errwrite = _subprocess.GetStdHandle(_subprocess.STD_ERROR_HANDLE) 

Exception Type: WindowsError at /blabla/pdf/10/ 
Exception Value: 6 The handle is invalid 
+1

IIS可能在不同的用戶下運行?這也是:http://stackoverflow.com/questions/3028786/how-cani-i-fix-error-6-the-handle-is-invalid-with-pyserial –

回答

0

終於得到了它,thank's to n1b0r。我必須更新python27/lib中CHECK_OUT方法/ subprocess.py這樣

來自:

if 'stdout' in kwargs: 
    raise ValueError('stdout argument not allowed, it will be overridden.') 
process = Popen(stdout=PIPE, *popenargs, **kwargs) 

到:

if 'stdout' in kwargs: 
     raise ValueError('stdout argument not allowed, it will be overridden.') 
kwargs.pop('stderr', None) 
process = Popen(stdout=PIPE, stderr=PIPE, stdin=PIPE, *popenargs, **kwargs) 

,使其工作在IIS,但如果給出一個錯誤使用django集成服務器。