pdfkit - python : 'str' 对象没有属性解码
pdfkit - python : 'str' object has no attribute decode
我正在尝试使用 pdfkit 将字符串 html 转换为 pdf 文件。这就是我正在做的
try:
options = {
'page-size': 'A4',
'margin-top': '0.75in',
'margin-right': '0.75in',
'margin-bottom': '0.75in',
'margin-left': '0.75in',
}
config = pdfkit.configuration(wkhtmltopdf="/usr/local/bin/wkhtmltopdf")
str= "Hello!!"
pdfkit.from_string(str,"Somefile.pdf",options=options,configuration=config)
return HttpResponse("Works")
except Exception as e:
return HttpResponse(str(e))
但是在 from_string
我得到异常 'str' object has no attribute decode。关于如何解决这个问题的任何建议?我正在使用 Python 3.5.1
尝试用此替换配置行 - 二进制文件的路径作为字节对象提供:
config = pdfkit.configuration(wkhtmltopdf=bytes("/usr/local/bin/wkhtmltopdf", 'utf8'))
我正在尝试使用 pdfkit 将字符串 html 转换为 pdf 文件。这就是我正在做的
try:
options = {
'page-size': 'A4',
'margin-top': '0.75in',
'margin-right': '0.75in',
'margin-bottom': '0.75in',
'margin-left': '0.75in',
}
config = pdfkit.configuration(wkhtmltopdf="/usr/local/bin/wkhtmltopdf")
str= "Hello!!"
pdfkit.from_string(str,"Somefile.pdf",options=options,configuration=config)
return HttpResponse("Works")
except Exception as e:
return HttpResponse(str(e))
但是在 from_string
我得到异常 'str' object has no attribute decode。关于如何解决这个问题的任何建议?我正在使用 Python 3.5.1
尝试用此替换配置行 - 二进制文件的路径作为字节对象提供:
config = pdfkit.configuration(wkhtmltopdf=bytes("/usr/local/bin/wkhtmltopdf", 'utf8'))