![](/img/trans.png)
[英]'str' object has no attribute 'decode' in python with unicodecsv
[英]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”对象没有属性解码。 关于如何解决这个问题的任何建议? 我正在使用 Python 3.5.1
尝试用这个替换配置行 - 二进制文件的路径作为字节对象提供:
config = pdfkit.configuration(wkhtmltopdf=bytes("/usr/local/bin/wkhtmltopdf", 'utf8'))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.