James Franco James Franco - 5 months ago 40
Python Question

pdfkit - python : 'str' object has no attribute decode

I am attempting to use pdfkit to convert string html to a pdf file. This is what I am doing

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!!"
return HttpResponse("Works")

except Exception as e:
return HttpResponse(str(e))

however at
I get the exception 'str' object has no attribute decode. Any suggestions on how I can fix this ? I am using Python 3.5.1


Try replacing the config line with this - path to the binary is provided as a bytes object:

config = pdfkit.configuration(wkhtmltopdf=bytes("/usr/local/bin/wkhtmltopdf", 'utf8'))

Reference: https://github.com/JazzCore/python-pdfkit/issues/32