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

Failed to load image at data:image/svg+xml, incorrect padding #515

Closed
sfdye opened this issue Oct 3, 2017 · 6 comments
Closed

Failed to load image at data:image/svg+xml, incorrect padding #515

sfdye opened this issue Oct 3, 2017 · 6 comments

Comments

@sfdye
Copy link
Contributor

sfdye commented Oct 3, 2017

I have an issue to render base64 svg to pdf that ends with something like:

"z48L2c+PC9zdmc+/"
(not ending in "=")

(The error message goes like: Incorrect padding)

I notice when I install/uninstall lxml, sometimes the problem goes away, but it's nondeterministic for different cases.

I am using pygal with weasyprint in Django and my code is like:

year_chart = pygal.HorizontalBar()
year_chart.add('2016', 4)
print(year_chart.render_data_uri())

The print will give different result based on whether lxml is installed or not.

I also saw #75, not sure if this is related.

@liZe
Copy link
Member

liZe commented Oct 6, 2017

That's really strange. render_data_uri uses the standard base64.b64encode to generate the base64 string. Could you provide a full example of base64 string that raises the "Incorrect padding" error?

@sfdye
Copy link
Contributor Author

sfdye commented Oct 6, 2017

PFA
error.log

@liZe
Copy link
Member

liZe commented Oct 6, 2017

You have an extra / at the end of the data URL, it's probably not related to Pygal or WeasyPrint 😉.

@sfdye
Copy link
Contributor Author

sfdye commented Oct 6, 2017

Interesting, but I didn't add the / myself. It's all rendered by the render_data_uri method.

My template goes like,

<embed type="image/svg+xml" src={{ year_chart|safe }}/>

Do you spot any error?

@liZe
Copy link
Member

liZe commented Oct 7, 2017

Yes! You have to add quotes after src=, or the slash used to close the tag is included in the src attribute!

<embed type="image/svg+xml" src="{{ year_chart|safe }}" />

@liZe liZe closed this as completed Oct 7, 2017
@sfdye
Copy link
Contributor Author

sfdye commented Oct 8, 2017

Oops, thanks for pointing out my silly mistake.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants