You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
PIL fails to open the bytes array with OSError: cannot identify image file <_io.BytesIO object at 0x7fde9c07d888>. Saving the image, Irfanview can open the file, but other viewers report it as invalid.
I don't have the same exact issue, but similar. I don't even get anything saved to the variable. The raised error prevents that When I use imgkit.from_url with path=False, I get some OSError. This doesn't happen when I provide a path.
I drilled down and inspected the module code to find that IMGKit.to_img is raising an error from stderr text from wkhtmltoimage. Below are the updates I made to IMGKit.to_img that I'm using by mocking the original function. I know it's hacky and doesn't solve the root cause, but it works for my purposes. Maybe I'll look further into it once I finish this project I'm working on. This is what the relevant part of my patch of to_img looks like...and now I have it working 100%.
Note: I also had to reimport subprocess and sys at the beginning of the updated function.
# 1. commented this out
# if "Error" in stderr:
# raise OSError("wkhtmltoimage reported an error:\n" + stderr)
if exit_code != 0:
xvfb_error = ""
if "QXcbConnection" in stderr:
xvfb_error = 'You need to install xvfb(sudo apt-get install xvfb, ' \
'yum install xorg-x11-server-Xvfb, etc), ' \
'then add option: {"xvfb": ""}.'
raise OSError( # 2. tabbed this raise over since we'd reach here as well...
"wkhtmltoimage exited with non-zero code {0}. error:\n{1}\n\n{2}".format(
exit_code, stderr, xvfb_error
)
)
Basically, I'm using the code as following:
PIL fails to open the bytes array with
OSError: cannot identify image file <_io.BytesIO object at 0x7fde9c07d888>
. Saving the image, Irfanview can open the file, but other viewers report it as invalid.Opening the image in a hex editor yields:
So there's some output stuff at the beginning of the file (line breaks added manually):
It looks like the stdout of something internal (
wkhtmltopdf
?) is getting captured into the "image" output, somehow.The text was updated successfully, but these errors were encountered: