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

AttributeError: 'NoneType' object has no attribute 'endswith' #8

Closed
ob7 opened this issue Aug 19, 2016 · 4 comments
Closed

AttributeError: 'NoneType' object has no attribute 'endswith' #8

ob7 opened this issue Aug 19, 2016 · 4 comments

Comments

@ob7
Copy link

ob7 commented Aug 19, 2016

Traceback (most recent call last):
File "./svg_stack.py", line 713, in
main()
File "./svg_stack.py", line 706, in main
layout.addSVG(fname,alignment=AlignCenter)
File "./svg_stack.py", line 632, in addSVG
svg_file = SVGFile(svg_file)
File "./svg_stack.py", line 181, in init
height, height_units = get_unit_attr(self._root.get('height'))
File "./svg_stack.py", line 44, in get_unit_attr
if value.endswith(unit_name):
AttributeError: 'NoneType' object has no attribute 'endswith'

I'm getting this error when running svg_stack via the following commands:
python2 ./svg_stack.py --direction=h --margin=100 virus.svg web-interface.svg > shapes.svg
python ./svg_stack.py --direction=h --margin=100 virus.svg web-interface.svg > shapes.svg
./svg_stack.py --direction=h --margin=100 virus.svg web-interface.svg > shapes.svg

I also tried running ./setup.py install and
svg_stack.py --direction=h --margin=100 virus.svg web-interface.svg > shapes.svg

gives same error.

I've also installed python-lxml and python3-lxml to no avail. Any idea what I'm doing wrong here?

@ob7
Copy link
Author

ob7 commented Aug 19, 2016

By the way, this doesn't happen when using the SVG's provided in the example, those work.

My SVG's look like this:

<?xml version="1.0" encoding="iso-8859-1"?>
<!-- Generator: Adobe Illustrator 19.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0)  -->
<svg version="1.1" id="Capa_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
     viewBox="0 0 511 511" style="enable-background:new 0 0 511 511;" xml:space="preserve">
<g>
    <path d="M39.5,103c1.97,0,3.91-0.8,5.3-2.2c1.4-1.39,2.2-3.33,2.2-5.3s-0.8-3.91-2.2-5.3c-1.39-1.4-3.32-2.2-5.3-2.2
        s-3.91,0.8-5.3,2.2c-1.4,1.39-2.2,3.33-2.2,5.3s0.8,3.91,2.2,5.3C35.59,102.2,37.53,103,39.5,103z"/>
    <path d="M63.5,103c1.98,0,3.91-0.8,5.3-2.2c1.4-1.39,2.2-3.33,2.2-5.3s-0.8-3.91-2.2-5.3c-1.39-1.4-3.33-2.2-5.3-2.2
        c-1.97,0-3.91,0.8-5.3,2.2c-1.4,1.39-2.2,3.33-2.2,5.3s0.8,3.91,2.2,5.3C59.59,102.2,61.52,103,63.5,103z"/>
    <path d="M87.5,103c1.97,0,3.91-0.8,5.3-2.2c1.4-1.39,2.2-3.33,2.2-5.3s-0.8-3.91-2.2-5.3c-1.39-1.4-3.33-2.2-5.3-2.2
        c-1.97,0-3.91,0.8-5.3,2.2c-1.4,1.39-2.2,3.33-2.2,5.3s0.8,3.91,2.2,5.3C83.59,102.2,85.53,103,87.5,103z"/>
    <path d="M119.5,103h304c4.142,0,7.5-3.358,7.5-7.5s-3.358-7.5-7.5-7.5h-304c-4.142,0-7.5,3.358-7.5,7.5S115.358,103,119.5,103z"/>
    <path d="M455.5,103h16c4.142,0,7.5-3.358,7.5-7.5s-3.358-7.5-7.5-7.5h-16c-4.142,0-7.5,3.358-7.5,7.5S451.358,103,455.5,103z"/>
    <path d="M255.5,327c4.142,0,7.5-3.358,7.5-7.5v-16c0-4.142-3.358-7.5-7.5-7.5s-7.5,3.358-7.5,7.5v16
        C248,323.642,251.358,327,255.5,327z"/>
    <path d="M207.131,305.243c2.085,1.289,4.423,1.939,6.767,1.939c1.954,0,3.913-0.452,5.733-1.362l18.436-9.218
        c5.427-2.714,8.934-8.816,8.934-15.582c0-9.385-6.781-17.02-15.116-17.02H213.9c-7.665,0-13.9,6.953-13.9,15.5v12.184
        C200,297.329,202.732,302.524,207.131,305.243z M215,279.5c0-0.193,0.021-0.361,0.05-0.5h16.383
        c0.217,0.288,0.567,0.963,0.567,2.055c0,1.25-0.51,2.022-0.642,2.131L215,291.365V279.5z"/>
    <path d="M272.934,296.602l18.436,9.218c1.82,0.91,3.778,1.362,5.733,1.362c2.344,0,4.682-0.65,6.767-1.939
        c4.398-2.719,7.131-7.914,7.131-13.559V279.5c0-8.547-6.235-15.5-13.9-15.5h-17.984c-8.335,0-15.116,7.635-15.116,17.055
        C264,287.786,267.507,293.888,272.934,296.602z M279.566,279h16.383c0.029,0.139,0.05,0.307,0.05,0.5v11.865l-16.304-8.148
        c-0.186-0.14-0.696-0.913-0.696-2.197C279,279.957,279.35,279.287,279.566,279z"/>
    <path d="M398.679,245.121c11.01-6.834,14.407-21.35,7.573-32.36c-3.112-5.014-7.954-8.649-13.634-10.237
        c-0.052-0.014-0.128-0.137-0.118-0.19c1.097-5.795-0.012-11.747-3.124-16.761c-6.834-11.009-21.352-14.407-32.359-7.573
        c-5.333,3.31-9.059,8.499-10.489,14.611c-0.84,3.591-0.83,7.248-0.007,10.735l-22.414,13.912
        C308.068,197.011,283.276,184,255.5,184s-52.568,13.011-68.608,33.257l-22.422-13.918c2.235-9.549-1.704-19.889-10.487-25.34
        c-5.333-3.31-11.635-4.345-17.748-2.915c-6.112,1.43-11.301,5.155-14.611,10.488c-3.112,5.014-4.222,10.966-3.125,16.761
        c0.01,0.054-0.064,0.175-0.118,0.19c-5.679,1.588-10.521,5.224-13.634,10.238c-6.833,11.01-3.435,25.526,7.574,32.36
        c5.333,3.31,11.637,4.345,17.748,2.915c3.591-0.84,6.863-2.473,9.623-4.758l28.915,17.947C168.21,264.596,168,268.024,168,271.5
        v18.899c0,7.307,2.025,14.266,5.614,20.268l-33.931,21.061c-7.566-6.24-18.58-7.299-27.362-1.848
        c-5.333,3.311-9.059,8.5-10.489,14.611c-1.431,6.112-0.395,12.416,2.915,17.749c3.112,5.013,7.954,8.649,13.634,10.238
        c0.052,0.014,0.128,0.137,0.118,0.19c-1.097,5.795,0.012,11.748,3.124,16.761c3.31,5.333,8.499,9.058,14.611,10.489
        c1.793,0.42,3.603,0.627,5.4,0.627c4.327,0,8.58-1.203,12.348-3.542c8.783-5.451,12.721-15.791,10.487-25.34l23.996-14.894
        c1.674,2.8,3.784,5.355,6.292,7.549l24.196,21.171c10.418,9.115,23.482,13.673,36.547,13.673s26.129-4.558,36.547-13.673
        l24.196-21.171c2.508-2.194,4.619-4.749,6.292-7.549l23.996,14.894c-2.234,9.549,1.704,19.889,10.487,25.34
        c3.768,2.339,8.021,3.542,12.348,3.542c1.797,0,3.607-0.208,5.4-0.627c6.112-1.43,11.301-5.155,14.611-10.488
        c3.112-5.013,4.222-10.966,3.125-16.761c-0.01-0.054,0.065-0.175,0.118-0.19c5.68-1.588,10.521-5.224,13.634-10.238
        c6.833-11.01,3.436-25.526-7.574-32.36c-5.333-3.31-11.635-4.345-17.748-2.915c-3.59,0.84-6.863,2.473-9.623,4.758l-33.922-21.055
        c3.59-6.002,5.614-12.961,5.614-20.268V271.5c0-3.476-0.21-6.904-0.606-10.275l28.924-17.952
        C378.882,249.513,389.897,250.572,398.679,245.121z M255.5,199c35.548,0,65.181,25.724,71.315,59.53
        c0.016,0.112,0.039,0.224,0.06,0.335C327.6,262.972,328,267.189,328,271.5v18.899c0,6.479-2.552,12.522-6.873,17.001
        c-0.082,0.082-0.163,0.166-0.242,0.253c-2.177,2.192-4.78,4-7.734,5.266l-36.605,15.688C273.788,329.788,272,332.5,272,335.5v8
        c0,0.276-0.224,0.5-0.5,0.5h-32c-0.276,0-0.5-0.224-0.5-0.5v-8c0-3-1.788-5.712-4.545-6.894l-36.605-15.688
        c-2.752-1.179-5.201-2.826-7.284-4.817c-0.356-0.465-0.762-0.874-1.2-1.233c-4.015-4.419-6.365-10.246-6.365-16.469V271.5
        c0-4.118,0.363-8.15,1.026-12.082c0.105-0.39,0.171-0.785,0.212-1.181c1.81-9.744,5.564-18.811,10.86-26.775
        c0.045-0.067,0.095-0.129,0.138-0.199c0.023-0.037,0.041-0.077,0.063-0.114C208.327,211.774,230.448,199,255.5,199z
         M142.263,227.219c-1.69-1.049-3.727-1.384-5.665-0.93c-1.937,0.453-3.614,1.658-4.663,3.348c-1.197,1.929-3.074,3.276-5.284,3.793
        s-4.49,0.144-6.42-1.054c-3.982-2.472-5.211-7.723-2.74-11.704c1.126-1.814,2.876-3.129,4.929-3.703
        c7.518-2.102,12.269-9.756,10.817-17.426c-0.396-2.094,0.005-4.247,1.13-6.06c1.198-1.929,3.074-3.276,5.285-3.794
        c2.21-0.516,4.49-0.143,6.419,1.055c3.982,2.472,5.211,7.722,2.739,11.705c-2.184,3.519-1.102,8.143,2.417,10.327l27.379,16.994
        c-2.729,5.009-4.983,10.313-6.701,15.85L142.263,227.219z M151.229,362.224c-3.52,2.184-4.602,6.808-2.417,10.327
        c2.472,3.982,1.243,9.233-2.739,11.705c-1.929,1.198-4.208,1.572-6.42,1.054c-2.21-0.517-4.087-1.865-5.285-3.794
        c-1.125-1.813-1.527-3.966-1.13-6.06c1.452-7.669-3.299-15.323-10.816-17.426c-2.053-0.574-3.803-1.889-4.929-3.702
        c-1.197-1.929-1.572-4.209-1.055-6.42c0.518-2.211,1.865-4.088,3.794-5.285c3.982-2.471,9.233-1.242,11.705,2.74
        c2.184,3.519,6.808,4.602,10.327,2.417l41.548-25.789c0.064,0.048,0.124,0.099,0.188,0.147v18.471c0,0.419,0.017,0.836,0.034,1.253
        L151.229,362.224z M306.365,353.027l-24.196,21.171c-15.204,13.303-38.135,13.303-53.339,0l-24.196-21.171
        c-3.581-3.133-5.635-7.659-5.635-12.417v-10.878l25,10.714v3.054c0,8.547,6.953,15.5,15.5,15.5h32c8.547,0,15.5-6.953,15.5-15.5
        v-3.054l25-10.714v10.878C312,345.368,309.946,349.894,306.365,353.027z M374.401,348.711c1.937-0.453,3.614-1.657,4.664-3.348
        c1.197-1.929,3.074-3.276,5.285-3.794c2.211-0.518,4.49-0.143,6.419,1.054c3.982,2.472,5.211,7.723,2.74,11.704
        c-1.126,1.813-2.876,3.128-4.929,3.702c-7.517,2.102-12.268,9.757-10.816,17.426c0.396,2.094-0.005,4.247-1.131,6.06
        c-1.197,1.929-3.074,3.276-5.284,3.793c-2.212,0.518-4.491,0.143-6.42-1.054c-3.982-2.472-5.211-7.722-2.739-11.705
        c2.184-3.519,1.102-8.143-2.417-10.327l-32.805-20.362c0.017-0.417,0.034-0.834,0.034-1.253v-18.471
        c0.064-0.047,0.124-0.099,0.188-0.147l41.549,25.789C370.427,348.83,372.465,349.164,374.401,348.711z M339.093,245.619
        c-1.718-5.537-3.971-10.841-6.701-15.85l27.38-16.994c1.69-1.049,2.895-2.726,3.348-4.663c0.453-1.937,0.119-3.974-0.931-5.664
        c-1.197-1.929-1.572-4.209-1.055-6.42c0.518-2.21,1.865-4.087,3.794-5.285c3.984-2.472,9.233-1.242,11.705,2.739
        c1.125,1.814,1.527,3.966,1.13,6.061c-1.452,7.669,3.299,15.324,10.817,17.426c2.052,0.574,3.803,1.889,4.929,3.702
        c2.472,3.982,1.243,9.233-2.739,11.705c-3.981,2.472-9.232,1.243-11.705-2.74c-2.184-3.519-6.808-4.602-10.327-2.417
        L339.093,245.619z"/>
    <path d="M471.5,56h-432C17.72,56,0,73.72,0,95.5v320C0,437.28,17.72,455,39.5,455h432c21.78,0,39.5-17.72,39.5-39.5v-320
        C511,73.72,493.28,56,471.5,56z M39.5,71h432c13.509,0,24.5,10.991,24.5,24.5V120H15V95.5C15,81.991,25.991,71,39.5,71z M471.5,440
        h-432C25.991,440,15,429.009,15,415.5V135h481v280.5C496,429.009,485.009,440,471.5,440z"/>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
</svg>

@math2001
Copy link

math2001 commented Mar 5, 2017

Same, this is annoying. But a small tweak did the job:

  def get_unit_attr(value):
      # coordinate handling from http://www.w3.org/TR/SVG11/coords.html#Units
      units = None # default (user)
+     if value is None:
+         return 0.0, 'px'
      for unit_name in UNITS:
          if value.endswith(unit_name):
              units = unit_name
              value = value[:-len(unit_name)]
              break
      val_float = float(value) # this will fail if units str not parsed
      return val_float, units

@briandavidelliott
Copy link

Thank you so much @math2001 !!! This helped get the script working for me!

astraw added a commit that referenced this issue Mar 13, 2021
@astraw
Copy link
Owner

astraw commented Mar 13, 2021

Confirmed fixed in 3c150a3. Sorry for the delay and thanks for the report.

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

4 participants