Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UnicodeDecodeError on using "quiet" option #71

Open
MLpranav opened this issue Apr 24, 2021 · 4 comments
Open

UnicodeDecodeError on using "quiet" option #71

MLpranav opened this issue Apr 24, 2021 · 4 comments
Assignees
Labels

Comments

@MLpranav
Copy link
Contributor

MLpranav commented Apr 24, 2021

This works fine.

img = imgkit.from_string(data.to_html(), False, options = {'width': 772, 'disable-smart-width': '', 'zoom' : 1.5})

This is the output.

Loading page (1/2)
Rendering (2/2)
Done

But if I add the "quiet" option to suppress output, it does not work.

img = imgkit.from_string(data.to_html(), False, options = {'width': 772, 'disable-smart-width': '', 'zoom' : 1.5, 'quiet': ''})

This is the error:

Traceback (most recent call last):
  File "D:\Libraries\Desktop\oi.py", line 139, in <module>
    img = imgkit.from_string(data.to_html(), False, options = {'width': 772, 'disable-smart-width': '', 'zoom' : 1.5, 'quiet': ''})
  File "C:\Users\prana\AppData\Roaming\Python\Python37\site-packages\imgkit\api.py", line 108, in from_string
    return rtn.to_img(output_path)
  File "C:\Users\prana\AppData\Roaming\Python\Python37\site-packages\imgkit\imgkit.py", line 242, in to_img
    stderr = stderr.decode("utf-8")
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte

This is data.to_html(), if it helps.

<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>Time</th>
      <th>CE</th>
      <th>PE</th>
      <th>PE-CE</th>
      <th>Price</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>16:33</td>
      <td>955450</td>
      <td>-12425</td>
      <td>-958314</td>
      <td>34129</td>
    </tr>
  </tbody>
</table>

If I remove False argument and save the image as a png file instead, it works.

@yosmelvin
Copy link

yosmelvin commented Jul 2, 2021

Hello guys any update about this bug? , actually I am facing same issue its because we try not to define output path and error UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte come out
and it happen on ubuntu OS which using xvfb for headless server

@MLpranav
Copy link
Contributor Author

MLpranav commented Jul 3, 2021

No update or fix yet I belive.

I suggest setting a dummy file or /dev/null as the output path as a temporary solution to the problem.

@arttuperala
Copy link

I also encountered this today and quickly looking at it, it looks like the issue is caused by a fallback in the error handling logic.

imgkit/src/imgkit/imgkit.py

Lines 241 to 242 in 1124d2e

stderr = stderr or stdout
stderr = stderr.decode("utf-8")

When the quiet option is used, bool(stderr) seems to evaluate to False, so it sets stderr to be equivalent to stdout, which is where the output file goes to. Then it tries to decode the file stream and fails.

imgkit/src/imgkit/imgkit.py

Lines 245 to 249 in 424f46c

stderr = stderr or stdout
try:
stderr = stderr.decode("utf-8")
except UnicodeDecodeError:
stderr = ""

I'm guessing previously it used to work since there was a try ... except to catch UnicodeDecodeError, but it was removed in commit eaa8cc3.

@ltfavas
Copy link

ltfavas commented Nov 15, 2021

Also suffering from this issue

jarrekk pushed a commit that referenced this issue Feb 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants