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

Invalid XML sometimes #7

Closed
peterbe opened this issue Feb 14, 2021 · 2 comments · Fixed by #8
Closed

Invalid XML sometimes #7

peterbe opened this issue Feb 14, 2021 · 2 comments · Fixed by #8

Comments

@peterbe
Copy link
Contributor

peterbe commented Feb 14, 2021

<path id=x6-"light" d="M50.7584999,...snip...122.446288 Z" fill-opacity="0.1" fill="#FFFFFF" fill-rule="evenodd"/>

I was getting

Traceback (most recent call last):
  File "dummy.py", line 24, in <module>
    get_random_avatar()
  File "/Users/peterbe/dev/PETERBECOM/django-peterbecom/peterbecom/homepage/views.py", line 1062, in get_random_avatar
    avatar.render_png_file(bytes)
  File "/Users/peterbe/.pyenv/versions/3.8.1/envs/django-peterbecom/lib/python3.8/site-packages/py_avataaars/__init__.py", line 341, in render_png_file
    svg2png(xml, write_to=output_file)
  File "/Users/peterbe/.pyenv/versions/3.8.1/envs/django-peterbecom/lib/python3.8/site-packages/cairosvg/__init__.py", line 55, in svg2png
    return surface.PNGSurface.convert(
  File "/Users/peterbe/.pyenv/versions/3.8.1/envs/django-peterbecom/lib/python3.8/site-packages/cairosvg/surface.py", line 127, in convert
    tree = Tree(
  File "/Users/peterbe/.pyenv/versions/3.8.1/envs/django-peterbecom/lib/python3.8/site-packages/cairosvg/parser.py", line 390, in __init__
    tree = ElementTree.fromstring(
  File "/Users/peterbe/.pyenv/versions/3.8.1/envs/django-peterbecom/lib/python3.8/site-packages/defusedxml/common.py", line 131, in fromstring
    parser.feed(text)
  File "/Users/peterbe/.pyenv/versions/3.8.1/Python.framework/Versions/3.8/lib/python3.8/xml/etree/ElementTree.py", line 1695, in feed
    self._raiseerror(v)
  File "/Users/peterbe/.pyenv/versions/3.8.1/Python.framework/Versions/3.8/lib/python3.8/xml/etree/ElementTree.py", line 1602, in _raiseerror
    raise err
xml.etree.ElementTree.ParseError: not well-formed (invalid token): line 1, column 12034

So I dumped the svg XML that gets sent to svg2png() to understand what's going on at line 1, column 12034.
And it's that:

id=x6-"light"

part.

@peterbe
Copy link
Contributor Author

peterbe commented Feb 14, 2021

Here's the problem:

peterbe added a commit to peterbe/py-avataaars that referenced this issue Feb 14, 2021
@peterbe
Copy link
Contributor Author

peterbe commented Feb 14, 2021

I tested it manually and now the error doesn't happen when I generate thousands of random avatars.

@kebu kebu closed this as completed in #8 Feb 16, 2021
kebu pushed a commit that referenced this issue Feb 16, 2021
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

Successfully merging a pull request may close this issue.

1 participant