Unexpected Exception: All strings must be XML compatible: Unicode or ASCII

Occasionally, I get an email from logger@indico about an “Unexpected Exception” of “All strings must be XML compatible: Unicode or ASCII, no NULL bytes or control characters”. The message contains the stack trace of the exception as follows:

indico.flask - ERROR errors.py:110 – All strings must be XML compatible: Unicode or ASCII, no NULL bytes or control characters

Traceback (most recent call last):
File “/opt/indico/.venv/lib/python3.9/site-packages/flask/app.py”, line 1517, in full_dispatch_request
rv = self.dispatch_request()
File “/opt/indico/.venv/lib/python3.9/site-packages/flask/app.py”, line 1503, in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
File “/opt/indico/.venv/lib/python3.9/site-packages/indico/web/flask/util.py”, line 79, in wrapper
return obj().process()
File “/opt/indico/.venv/lib/python3.9/site-packages/indico/web/rh.py”, line 281, in process
res = self._do_process()
File “/opt/indico/.venv/lib/python3.9/site-packages/indico/web/rh.py”, line 252, in _do_process
rv = self._process()
File “/opt/indico/.venv/lib/python3.9/site-packages/indico/modules/categories/controllers/display.py”, line 370, in _process
buf = serialize_category_atom(self.category,
File “/opt/indico/.venv/lib/python3.9/site-packages/indico/modules/categories/serialize.py”, line 95, in serialize_category_atom
return BytesIO(feed.atom_str(pretty=True))
File “/opt/indico/.venv/lib/python3.9/site-packages/feedgen/feed.py”, line 222, in atom_str
feed, doc = self._create_atom(extensions=extensions)
File “/opt/indico/.venv/lib/python3.9/site-packages/feedgen/feed.py”, line 198, in _create_atom
entry = entry.atom_entry()
File “/opt/indico/.venv/lib/python3.9/site-packages/feedgen/entry.py”, line 110, in atom_entry
title.text = self.__atom_title
File “src/lxml/etree.pyx”, line 1041, in lxml.etree._Element.text.set
File “src/lxml/apihelpers.pxi”, line 748, in lxml.etree._setNodeText
File “src/lxml/apihelpers.pxi”, line 736, in lxml.etree._createTextNode
File “src/lxml/apihelpers.pxi”, line 1541, in lxml.etree._utf8
ValueError: All strings must be XML compatible: Unicode or ASCII, no NULL bytes or control characters

{‘data’: {‘get’: {},
‘headers’: {‘Accept-Encoding’: ‘gzip’,
‘Cdn-Loop’: ‘cloudflare’,
‘Cf-Connecting-Ip’: ‘18.236.186.155’,
‘Cf-Ipcountry’: ‘US’,
‘Cf-Ray’: ‘7a934dce2e89ec7c-SEA’,
‘Cf-Visitor’: ‘{“scheme”:“https”}’,
‘Connection’: ‘Keep-Alive’,
‘Host’: ‘**’,
‘User-Agent’: ‘okhttp/4.10.0’,
‘X-Forwarded-For’: ‘18.236.186.155’,
‘X-Forwarded-Proto’: ‘https’},
‘json’: None,
‘post’: {},
‘url’: {‘category_id’: 37}},
‘endpoint’: ‘categories.export_atom’,
‘id’: ‘5ac858bfa1a64f88’,
‘ip’: ‘172.71.150.177’,
‘method’: ‘GET’,
‘referrer’: None,
‘rh’: ‘RHExportCategoryAtom’,
‘time’: ‘2023-03-17T07:50:51.368139’,
‘url’: ‘****************/category/37/events.atom’,
‘user’: None,
‘user_agent’: ‘okhttp/4.10.0’}

What causes this exception and how to avoid it?

This seems to happen when some access one of the event atom feeds. And as atom requires valid xml you get this error. You probably have something in an event title that causes the problem. Check the titles in category/37.

Thank you for the hint. It was a special character in the title of an event in a sub category!