question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xfe in position 28: invalid start byte

See original GitHub issue

Latest release has introduced a new bug (this same code worked on 0.5.0)

File "/usr/local/lib/python3.5/dist-packages/pdfkit/api.py", line 72, in from_string
   return r.to_pdf(output_path)

 File "/usr/local/lib/python3.5/dist-packages/pdfkit/pdfkit.py", line 146, in to_pdf
   if 'cannot connect to X server' in stderr.decode('utf-8'):

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xfe in position 28: invalid start byte

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:12
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
vbukhonovcommented, Aug 16, 2017

Getting the same error. pdfkit==0.6.1

1reaction
Schnodderbalkencommented, Oct 15, 2018

I can definitely confirm that this issue still persists in version 0.6.1. I tried it in a clean docker environment. In order to reproduce this error, the following command is enough: pdfkit.from_string('<html></html>', False).to_pdf(False).decode(). This leads to: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xfe in position 785: invalid start byte

@JazzCore do you have any idea why this is?

Update Downgrading to 0.5.0 also did not lead to success

If I look at the file I can see that there are a lot of non-byte-characters at the beginning which seem to be the shell output of the executed command:

Loading page (1/2)
[>                                                           ] 0%
[======>                                                     ] 10%
[=========>                                                  ] 16%
[============>                                               ] 21%
[================>                                           ] 27%
[===================>                                        ] 33%
[=======================>                                    ] 39%
[==========================>                                 ] 44%
[==============================>                             ] 50%
[============================================================] 100%
Printing pages (2/2)                                               
%PDF-1.4
1 0 obj
<<
/Title (��)
/Creator (��wkhtmltopdf 0.12.3.2)
/Producer (��Qt 5.7.1)
/CreationDate (D:20181015205815)
>>
endobj
2 0 obj
<<
/Type /Catalog
/Pages 3 0 R
>>
endobj
4 0 obj
<<
/Type /ExtGState
/SA true
/SM 0.02
/ca 1.0
/CA 1.0
/AIS false
/SMask /None>>
endobj
5 0 obj
[/Pattern /DeviceRGB]
endobj
6 0 obj
<<
/Type /Page
/Parent 3 0 R
/Contents 7 0 R
/Resources 9 0 R
/Annots 10 0 R
/MediaBox [0 0 595 842]
>>
endobj
9 0 obj
<<
/ColorSpace <<
/PCSp 5 0 R
/CSp /DeviceRGB
/CSpg /DeviceGray
>>
/ExtGState <<
/GSa 4 0 R
>>
/Pattern <<
>>
/Font <<
>>
/XObject <<
>>
>>
endobj
10 0 obj
[ ]
endobj
7 0 obj
<<
/Length 8 0 R
/Filter /FlateDecode
>>
stream

Okay, this can be suppressed by using the 'quiet' option. However, this doesn’t solve the problem either.

Update Using decode(errors='ignore') works…

Read more comments on GitHub >

github_iconTop Results From Across the Web

error UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff ...
When it tries this, it encounters a byte sequence which is not allowed in utf-8-encoded strings (namely this 0xff at position 0).
Read more >
Python UnicodeDecodeError utf-8 codec can t decode byte ...
utf-8 ' codec can't decode byte 0xa0 in position 10: invalid start byte. my code import wordcloud import numpy as np from matplotlib...
Read more >
How to fix error UnicodeDecodeError utf 8 codec cant decode ...
How to Fix Error "UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte" in Python. The below error is...
Read more >
'utf-8' codec can't decode byte 0xff in position 0 | bobbyhadz
The Python "UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte" occurs when we specify an incorrect ...
Read more >
'utf-8' codec can't decode byte 0xfe in position 341
Find professional answers about "'utf-8' codec can't decode byte 0xfe in position 341: invalid start byte" in 365 Data Science's Q&A Hub. Join...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found