Skip to content

Commit 8261c09

Browse files
committed
fix python 3 errors
1 parent c1fe0aa commit 8261c09

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

pdfkit/pdfkit.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,18 +98,18 @@ def to_pdf(self, path=None):
9898
if self.source.isString() or (self.source.isFile() and self.css):
9999
input = self.source.to_s().encode('utf-8')
100100
elif self.source.isFileObj():
101-
input = self.source.source.read()
101+
input = self.source.source.read().encode('utf-8')
102102
else:
103103
input = None
104104
stdout, stderr = result.communicate(input=input)
105105

106-
if 'Error' in stderr:
107-
raise IOError('wkhtmltopdf reported an error:\n' + stderr)
106+
if 'Error' in stderr.decode('utf-8'):
107+
raise IOError('wkhtmltopdf reported an error:\n' + stderr.decode('utf-8'))
108108

109109
# Since wkhtmltopdf sends its output to stderr we will capture it
110110
# and properly send to stdout
111111
if '--quiet' not in args:
112-
sys.stdout.write(stderr)
112+
sys.stdout.write(stderr.decode('utf-8'))
113113

114114
if not path:
115115
return stdout

tests/pdfkit-tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ def test_pdf_generation_from_file_like(self):
272272
with open('fixtures/example.html', 'r') as f:
273273
r = pdfkit.PDFKit(f, 'file')
274274
output = r.to_pdf()
275-
self.assertEqual(output[:4], '%PDF')
275+
self.assertEqual(output[:4].decode('utf-8'), '%PDF')
276276

277277
def test_raise_error_with_wrong_css_path(self):
278278
css = 'fixtures/wrongpath.css'

0 commit comments

Comments
 (0)