You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
An escape error of re.py (re.error: bad escape \s at position 0) in "utils/logloader.py" based on Python3.7 #50
Dear authors,
Thanks for your work. When I ran the file, "MoLFI_demo.py", based on Python3.7, I got the error as following.
Traceback (most recent call last):
File "~/anaconda3/envs/tf/lib/python3.7/sre_parse.py", line 1021, in parse_template
this = chr(ESCAPES[this][1])
KeyError: '\\s'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "MoLFI_demo.py", line 14, in <module>
parser.parse(log_file)
File "../logparser/MoLFI/MoLFI.py", line 41, in parse
loader = logloader.LogLoader(self.log_format, self.n_workers)
File "../logparser/utils/logloader.py", line 38, in __init__
self.headers, self.regex = self._generate_logformat_regex(self.logformat)
File "../logparser/utils/logloader.py", line 79, in _generate_logformat_regex
splitter = re.sub(' +', '\s+', splitters[k])
File "~/anaconda3/envs/tf/lib/python3.7/re.py", line 192, in sub
return _compile(pattern, flags).sub(repl, string, count)
File "~/anaconda3/envs/tf/lib/python3.7/re.py", line 309, in _subx
template = _compile_repl(template, pattern)
File "~/anaconda3/envs/tf/lib/python3.7/re.py", line 300, in _compile_repl
return sre_parse.parse_template(repl, pattern)
File "~/anaconda3/envs/tf/lib/python3.7/sre_parse.py", line 1024, in parse_template
raise s.error('bad escape %s' % this, len(this))
re.error: bad escape \s at position 0
File "/usr/local/Cellar/python@3.9/3.9.12_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/sre_parse.py", line 1041, in parse_template
this = chr(ESCAPES[this][1])
KeyError: '\s'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.9/site-packages/spyder_kernels/py3compat.py", line 356, in compat_exec
exec(code, globals, locals)
File "/Users/devharsh/Downloads/Drain_demo.py", line 28, in
parser.parse(log_file)
File "/Users/devharsh/Downloads/Drain.py", line 293, in parse
self.outputResult(logCluL)
File "/Users/devharsh/Downloads/Drain.py", line 224, in outputResult
self.df_log["ParameterList"] = self.df_log.apply(self.get_parameter_list, axis=1)
File "/usr/local/lib/python3.9/site-packages/pandas/core/frame.py", line 8839, in apply
return op.apply().finalize(self, method="apply")
File "/usr/local/lib/python3.9/site-packages/pandas/core/apply.py", line 727, in apply
return self.apply_standard()
File "/usr/local/lib/python3.9/site-packages/pandas/core/apply.py", line 851, in apply_standard
results, res_index = self.apply_series_generator()
File "/usr/local/lib/python3.9/site-packages/pandas/core/apply.py", line 867, in apply_series_generator
results[i] = self.f(v)
File "/Users/devharsh/Downloads/Drain.py", line 347, in get_parameter_list
template_regex = re.sub(r'\ +', r'\s+', template_regex)
File "/usr/local/Cellar/python@3.9/3.9.12_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/re.py", line 210, in sub
return _compile(pattern, flags).sub(repl, string, count)
File "/usr/local/Cellar/python@3.9/3.9.12_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/re.py", line 327, in _subx
template = _compile_repl(template, pattern)
File "/usr/local/Cellar/python@3.9/3.9.12_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/re.py", line 318, in _compile_repl
return sre_parse.parse_template(repl, pattern)
File "/usr/local/Cellar/python@3.9/3.9.12_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/sre_parse.py", line 1044, in parse_template
raise s.error('bad escape %s' % this, len(this))
Just adding this in case someone else has this problem in 2022 when using python 3.8.10.
I changed the following line:
splitter = re.sub(' +', '\s+', splitters[k])
to
splitter = re.sub(' +', '\\\s+', splitters[k])
and that fixed it. Note that I changed this only in the function def _generate_logformat_regex(self, logformat): of the file Spell/Spell.py (because I was using spell) and not in utils/logloader.py.
Activity
zhujiem commentedon Oct 11, 2019
Please use Python 3.6
ankit-nassa commentedon Oct 11, 2019
You can also try replacing import re to import regex as re
fuyunliu commentedon Oct 14, 2019
template_regex = re.sub(r'\\ +', r'\s+', template_regex)what do you mean sub
\\ +with\s+?shoaib-intro commentedon May 9, 2022
devharsh commentedon May 27, 2022
Traceback (most recent call last):
File "/usr/local/Cellar/python@3.9/3.9.12_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/sre_parse.py", line 1041, in parse_template
this = chr(ESCAPES[this][1])
KeyError: '\s'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.9/site-packages/spyder_kernels/py3compat.py", line 356, in compat_exec
exec(code, globals, locals)
File "/Users/devharsh/Downloads/Drain_demo.py", line 28, in
parser.parse(log_file)
File "/Users/devharsh/Downloads/Drain.py", line 293, in parse
self.outputResult(logCluL)
File "/Users/devharsh/Downloads/Drain.py", line 224, in outputResult
self.df_log["ParameterList"] = self.df_log.apply(self.get_parameter_list, axis=1)
File "/usr/local/lib/python3.9/site-packages/pandas/core/frame.py", line 8839, in apply
return op.apply().finalize(self, method="apply")
File "/usr/local/lib/python3.9/site-packages/pandas/core/apply.py", line 727, in apply
return self.apply_standard()
File "/usr/local/lib/python3.9/site-packages/pandas/core/apply.py", line 851, in apply_standard
results, res_index = self.apply_series_generator()
File "/usr/local/lib/python3.9/site-packages/pandas/core/apply.py", line 867, in apply_series_generator
results[i] = self.f(v)
File "/Users/devharsh/Downloads/Drain.py", line 347, in get_parameter_list
template_regex = re.sub(r'\ +', r'\s+', template_regex)
File "/usr/local/Cellar/python@3.9/3.9.12_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/re.py", line 210, in sub
return _compile(pattern, flags).sub(repl, string, count)
File "/usr/local/Cellar/python@3.9/3.9.12_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/re.py", line 327, in _subx
template = _compile_repl(template, pattern)
File "/usr/local/Cellar/python@3.9/3.9.12_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/re.py", line 318, in _compile_repl
return sre_parse.parse_template(repl, pattern)
File "/usr/local/Cellar/python@3.9/3.9.12_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/sre_parse.py", line 1044, in parse_template
raise s.error('bad escape %s' % this, len(this))
error: bad escape \s
devharsh commentedon May 28, 2022
error when I changed import re to import regex as re
Traceback (most recent call last):
File "/usr/local/lib/python3.9/site-packages/spyder_kernels/py3compat.py", line 356, in compat_exec
exec(code, globals, locals)
File "/Users/devharsh/Downloads/Drain_demo.py", line 28, in
parser.parse(log_file)
File "/Users/devharsh/Downloads/Drain.py", line 293, in parse
self.outputResult(logCluL)
File "/Users/devharsh/Downloads/Drain.py", line 224, in outputResult
self.df_log["ParameterList"] = self.df_log.apply(self.get_parameter_list, axis=1)
File "/usr/local/lib/python3.9/site-packages/pandas/core/frame.py", line 8839, in apply
return op.apply().finalize(self, method="apply")
File "/usr/local/lib/python3.9/site-packages/pandas/core/apply.py", line 727, in apply
return self.apply_standard()
File "/usr/local/lib/python3.9/site-packages/pandas/core/apply.py", line 851, in apply_standard
results, res_index = self.apply_series_generator()
File "/usr/local/lib/python3.9/site-packages/pandas/core/apply.py", line 867, in apply_series_generator
results[i] = self.f(v)
File "/Users/devharsh/Downloads/Drain.py", line 347, in get_parameter_list
template_regex = re.sub(r'\ +', r'\s+', template_regex)
File "/usr/local/lib/python3.9/site-packages/regex/regex.py", line 278, in sub
return pat.sub(repl, string, count, pos, endpos, concurrent, timeout)
File "/usr/local/lib/python3.9/site-packages/regex/regex.py", line 700, in _compile_replacement_helper
is_group, items = _compile_replacement(source, pattern, is_unicode)
File "/usr/local/lib/python3.9/site-packages/regex/_regex_core.py", line 1737, in _compile_replacement
raise error("bad escape \%s" % ch, source.string, source.pos)
error: bad escape \s
estebanpw commentedon Aug 3, 2022
Just adding this in case someone else has this problem in 2022 when using python 3.8.10.
I changed the following line:
splitter = re.sub(' +', '\s+', splitters[k])to
splitter = re.sub(' +', '\\\s+', splitters[k])and that fixed it. Note that I changed this only in the function
def _generate_logformat_regex(self, logformat):of the fileSpell/Spell.py(because I was using spell) and not inutils/logloader.py.Jun-jie-Huang commentedon Feb 24, 2023
Try to degrade regex
pip install regex=2022.3.2if it still raises exceptions. This works for me.khawar-islam commentedon Jun 7, 2023
Hello @estebanpw I implemented your suggestion but still the problem is same. Any idea how to fix?
shoaib-intro commentedon Jun 7, 2023
also you can try
import regex as reif import throw error usepip install regexbut keep @estebanpw Suggestion also this is additional to that.Update logparser v1.0.0 to support Python 3 compatibility
Update logparser v1.0.0 to support Python 3 compatibility
Update logparser v1.0.0 to support Python 3 compatibility
Update logparser v1.0.0 to support Python 3 compatibility
Update logparser v1.0.0 to support Python 3 compatibility
Update logparser v1.0.0 to support Python 3 compatibility
Update logparser v1.0.0 to support Python 3 compatibility