pisa 유틸리티에서 html2pdf를 변환하려고합니다. 아래 코드를 확인하십시오. 내가 알 수없는 오류가 발생했습니다.Python에서 xhtml2pdf.pisa를 사용하여 아랍어 페이지로 변환
Traceback (most recent call last):
File "dewa.py", line 27, in <module>
html = html.encode(enc, 'replace')
UnicodeDecodeError: 'ascii' codec can't decode byte 0xd9 in position 203: ordinal not in range(128)
여기에서 코드를 확인하십시오.
from cStringIO import StringIO
from grab import Grab
from grab.tools.lxml_tools import drop_node, render_html
from grab.tools.text import remove_bom
from lxml import etree
import grab.error
import inspect
import lxml
import os
import sys
import xhtml2pdf.pisa as pisa
enc = 'utf-8'
filePath = '~/Desktop/dewa'
##############################
g = Grab()
g.go('http://www.dewa.gov.ae/arabic/aboutus/dewahistory.aspx')
html = g.response.body
html = html.replace('bgcolor="EDF389"', 'bgcolor="#EDF389"')
''' clear page '''
html = html.encode(enc, 'replace')
print html
f = file(filePath + '.html' , 'wb')
f.write(html)
f.flush()
f.close()
''' Save PDF '''
pdfresult = StringIO()
pdf = pisa.pisaDocument(StringIO(html), pdfresult, encoding = enc)
f = file(filePath + '.pdf', 'wb')
f.write(pdfresult.getvalue())
f.flush()
f.close()
pdfresult.close()
스택 오버플로에 ** 바이트를 디코딩 할 수 ** '아스키'코덱에 대한 Google 검색 12K + 결과를 반환합니다. 그걸로 시작하고 싶을지도 모릅니다 ... – dda