Distrotech / reportlab

Mirror of https://bitbucket.org/rptlab/reportlab
Other
61 stars 41 forks source link

'ParaFrag' object has no attribute '_selfClosingTag' #14

Closed 0x78f1935 closed 3 years ago

0x78f1935 commented 4 years ago

This happens on a selfclosing br tag. </br>.

Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/flask/app.py", line 2447, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/local/lib/python3.8/site-packages/flask/app.py", line 1952, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/local/lib/python3.8/site-packages/flask_cors/extension.py", line 161, in wrapped_function
    return cors_after_request(app.make_response(f(*args, **kwargs)))
  File "/usr/local/lib/python3.8/site-packages/flask/app.py", line 1821, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/local/lib/python3.8/site-packages/flask/_compat.py", line 39, in reraise
    raise value
  File "/usr/local/lib/python3.8/site-packages/flask/app.py", line 1950, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/local/lib/python3.8/site-packages/flask/app.py", line 1936, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/usr/local/lib/python3.8/site-packages/connexion/decorators/decorator.py", line 48, in wrapper
    response = function(request)
  File "/usr/local/lib/python3.8/site-packages/connexion/decorators/security.py", line 327, in wrapper
    return function(request)
  File "/usr/local/lib/python3.8/site-packages/connexion/decorators/uri_parsing.py", line 144, in wrapper
    response = function(request)
  File "/usr/local/lib/python3.8/site-packages/connexion/decorators/validation.py", line 184, in wrapper
    response = function(request)
  File "/usr/local/lib/python3.8/site-packages/connexion/decorators/parameter.py", line 121, in wrapper
    return function(**kwargs)
  File "/workspaceFolder/backend/api/v1/pdf/__init__.py", line 99, in string_to_pdf
    content = Paragraph(data['content'], style)
  File "/usr/local/lib/python3.8/site-packages/reportlab/platypus/paragraph.py", line 1765, in __init__
    self._setup(text, style, bulletText or getattr(style,'bulletText',None), frags, cleanBlockQuotedText)
  File "/usr/local/lib/python3.8/site-packages/reportlab/platypus/paragraph.py", line 1786, in _setup
    style, frags, bulletTextFrags = _parser.parse(text,style)
  File "/usr/local/lib/python3.8/site-packages/reportlab/platypus/paraparser.py", line 3224, in parse
    annotateException('\nparagraph text %s caused exception' % ascii(text))
  File "/usr/local/lib/python3.8/site-packages/reportlab/lib/utils.py", line 1397, in annotateException
    rl_reraise(t,v,b)
  File "/usr/local/lib/python3.8/site-packages/reportlab/lib/utils.py", line 150, in rl_reraise
    raise v
  File "/usr/local/lib/python3.8/site-packages/reportlab/platypus/paraparser.py", line 3222, in parse
    self.feed(text)
  File "/usr/local/lib/python3.8/html/parser.py", line 111, in feed
    self.goahead(0)
  File "/usr/local/lib/python3.8/html/parser.py", line 173, in goahead
    k = self.parse_endtag(i)
  File "/usr/local/lib/python3.8/html/parser.py", line 421, in parse_endtag
    self.handle_endtag(elem)
  File "/usr/local/lib/python3.8/site-packages/reportlab/platypus/paraparser.py", line 3258, in handle_endtag
    end()
  File "/usr/local/lib/python3.8/site-packages/reportlab/platypus/paraparser.py", line 2866, in end_br
    if not (frag._selfClosingTag=='br' and frag.lineBreak):
AttributeError: 'ParaFrag' object has no attribute '_selfClosingTag'
paragraph text '<para>Hi, </br> Thanks! </br> Greetings</para>' caused exception

Styling

from reportlab.lib.styles import ParagraphStyle
style = ParagraphStyle("")
style.fontSize = font_size
style.leading = style.fontSize*1.2
style.alignment = TA_LEFT
style.wordWrap = 'LTR'
content = Paragraph(data['content'], style)

edit: data['content'] -> Hi, </br> Thanks! </br> Greetings

Is there any solution available to solve this issue? Thanks in advance!

0x78f1935 commented 3 years ago

Project seems dead

stratofax commented 2 years ago

Try this: replace </br> with <br />