2016-10-15 18 views
1

pdfkitを使用して文字列htmlをpdfファイルに変換しようとしています。これは私が私が例外「str」はオブジェクトが属性デコードを持っていない取得from_stringでしかし pdfkit - 'str'オブジェクトに属性デコードがありません

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)) 

をやっているものです。どのように私はこれを修正することができます上の任意の提案?私はこれで設定行を交換してみてくださいPythonの3.5.1

答えて

1

使用しています - バイナリへのパスがbytesオブジェクトとして提供されています

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

参考:トリックをしたhttps://github.com/JazzCore/python-pdfkit/issues/32

+0

完璧! !ありがとう –

+0

しかし、それは私にエラーを与える: wkhtmltopdfがエラーを報告しました: ネットワークエラーのためコード1で終了:ConnectionRefusedError –

関連する問題