Getting AttributeError: 'Node' object has no attribute 'xml_tree' when parsing svg
- Dominant language
- Python
- Stars
- 951
- Forks
- 166
- PR merge metrics
- No merged PRs in 30d
Description
When I try to run `svg2png` on this SVG from the [yr.no weather symbols](https://github.com/YR/weather-symbols) I get the following error.
### SVG
```svg
```
### Error
```python
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
in ()
1 from IPython.display import Image
----> 2 Image(glyph.to_png(scale=5), retina=True)
~/metglyphs/__init__.py in to_png(self, scale)
68 """Convert to a png."""
69 return cairosvg.svg2png(bytestring=self.svg,
---> 70 scale=scale)
71
72 def to_np_array(self, scale=1):
/opt/conda/lib/python3.6/site-packages/cairosvg/__init__.py in (*args, **kwargs)
43 # Two lambdas needed for the closure
44 lambda surface_type: lambda *args, **kwargs:
---> 45 surface_type.convert(*args, **kwargs))(_surface_type)
46 _name = 'svg2{}'.format(_output_format.lower())
47 _function.__name__ = _name
/opt/conda/lib/python3.6/site-packages/cairosvg/surface.py in convert(cls, bytestring, **kwargs)
136 output = write_to or io.BytesIO()
137 instance = cls(
--> 138 tree, output, dpi, None, parent_width, parent_height, scale)
139 instance.finish()
140 if write_to is None:
/opt/conda/lib/python3.6/site-packages/cairosvg/surface.py in __init__(self, tree, output, dpi, parent_surface, parent_width, parent_height, scale)
193 width, height, viewbox, scale, preserved_ratio(tree))
194 self.context.move_to(0, 0)
--> 195 self.draw(tree)
196
197 @property
/opt/conda/lib/python3.6/site-packages/cairosvg/surface.py in draw(self, node)
411 if display and node.tag not in INVISIBLE_TAGS:
412 for child in node.children:
--> 413 self.draw(child)
414
415 # Apply filter, mask and opacity
/opt/conda/lib/python3.6/site-packages/cairosvg/surface.py in draw(self, node)
351 if node.tag in TAGS:
352 try:
--> 353 TAGS[node.tag](self, node)
354 except PointError:
355 # Error in point parsing, do nothing
/opt/conda/lib/python3.6/site-packages/cairosvg/defs.py in use(surface, node)
376 tree['width'], tree['height'] = node['width'], node['height']
377
--> 378 surface.draw(tree)
379 node.get('fill', None)
380 node.get('stroke', None)
/opt/conda/lib/python3.6/site-packages/cairosvg/surface.py in draw(self, node)
411 if display and node.tag not in INVISIBLE_TAGS:
412 for child in node.children:
--> 413 self.draw(child)
414
415 # Apply filter, mask and opacity
/opt/conda/lib/python3.6/site-packages/cairosvg/surface.py in draw(self, node)
419 apply_filter_before_painting(self, node, filter_)
420 if mask in self.masks:
--> 421 paint_mask(self, node, mask, opacity)
422 else:
423 self.context.paint_with_alpha(opacity)
/opt/conda/lib/python3.6/site-packages/cairosvg/defs.py in paint_mask(surface, node, name, opacity)
162
163 from .surface import SVGSurface # circular import
--> 164 mask_surface = SVGSurface(mask_node, None, surface.dpi, surface)
165 surface.context.save()
166 surface.context.translate(x, y)
/opt/conda/lib/python3.6/site-packages/cairosvg/surface.py in __init__(self, tree, output, dpi, parent_surface, parent_width, parent_height, scale)
193 width, height, viewbox, scale, preserved_ratio(tree))
194 self.context.move_to(0, 0)
--> 195 self.draw(tree)
196
197 @property
/opt/conda/lib/python3.6/site-packages/cairosvg/surface.py in draw(self, node)
411 if display and node.tag not in INVISIBLE_TAGS:
412 for child in node.children:
--> 413 self.draw(child)
414
415 # Apply filter, mask and opacity
/opt/conda/lib/python3.6/site-packages/cairosvg/surface.py in draw(self, node)
351 if node.tag in TAGS:
352 try:
--> 353 TAGS[node.tag](self, node)
354 except PointError:
355 # Error in point parsing, do nothing
/opt/conda/lib/python3.6/site-packages/cairosvg/defs.py in use(surface, node)
363 tree = Tree(
364 url=href, url_fetcher=node.url_fetcher, parent=node,
--> 365 tree_cache=surface.tree_cache, unsafe=node.unsafe)
366
367 if not match_features(tree.xml_tree):
/opt/conda/lib/python3.6/site-packages/cairosvg/parser.py in __init__(self, **kwargs)
384 while root_parent.parent:
385 root_parent = root_parent.parent
--> 386 tree = root_parent.xml_tree
387 else:
388 if not bytestring:
AttributeError: 'Node' object has no attribute 'xml_tree'
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Reproduce the failure with the weather-symbols SVG and the svg2png call shown in the issue. Start in cairosvg/defs.py at use and paint_mask, then trace the related Tree handling in cairosvg/parser.py; done means this SVG converts without the Node.xml_tree AttributeError.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- computer-graphics
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100