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

render_data_uri fails with TypeError: a bytes-like object is required, not 'str' #529

Open
rouilj opened this issue May 26, 2022 · 1 comment

Comments

@rouilj
Copy link

rouilj commented May 26, 2022

Running:

        elif self.output_type == 'data:':
            image = chart.render_data_uri(is_unicode=True)

results in a traceback (with or without is_unicode being passed). Here is the traceback:

[/usr/lib/python3.6/base64.py](file://usr/lib/python3.6/base64.py) in b64encode(s='<svg xmlns:xlink="http://www.w3.org/1999/xlink" ...gends" transform="translate(390, 82)"/></g></svg>', altchars=None)
   56     application to e.g. generate url or filesystem safe Base64 strings.
   57     """
   58     encoded = binascii.b2a_base64(s, newline=False)
      encoded = undefined, global binascii = <module 'binascii' (built-in)>, global b2a_base64 = undefined, s = '<svg xmlns:xlink="http://www.w3.org/1999/xlink" ...gends" transform="translate(390, 82)"/></g></svg>', global newline = undefined
   59     if altchars is not None:
   60         assert len(altchars) == 2, repr(altchars)

[/usr/local/lib/python3.6/dist-packages/pygal/graph/public.py](file://usr/local/lib/python3.6/dist-packages/pygal/graph/public.py) in render_data_uri(self=<pygal.graph.pie.Pie object>, **kwargs={'force_uri_protocol': 'https', 'is_unicode': True})
  105         return "data:image/svg+xml;charset=utf-8;base64,%s" % (
  106             base64.b64encode(
  107                 self.render(**kwargs)
      self = <pygal.graph.pie.Pie object>, global render = undefined, kwargs = {'force_uri_protocol': 'https', 'is_unicode': True}
  108             ).decode('utf-8').replace('\n', '')
  109         )

looks like self.render() is returning a string when it needs to be bytes??

@GarrettPetersen
Copy link

Just wanted to chime in to say I have the same issue. It's easy enough to make a workaround, but we should fix this in pygal.

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