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

hass-cli state history ENTITY fails with bad escape \d at position 7 #394

Open
ramrom opened this issue Dec 11, 2022 · 9 comments
Open

hass-cli state history ENTITY fails with bad escape \d at position 7 #394

ramrom opened this issue Dec 11, 2022 · 9 comments

Comments

@ramrom
Copy link

ramrom commented Dec 11, 2022

Running a hass-cli state history ENTITY command for any entity fails:

$ hass-cli state history sun.sun
error: error: bad escape \d at position 7
Run with -x to see full exception information
$

I ran it with the -x option as suggested:

$ hass-cli -x state history sun.sun
bad escape \d at position 7
Traceback (most recent call last):
  File "/home/ramrom/.local/lib/python3.10/site-packages/homeassistant_cli/cli.py", line 40, in run
    result = cli.main(standalone_mode=False)
  File "/usr/lib/python3/dist-packages/click/core.py", line 1053, in main
    rv = self.invoke(ctx)
  File "/usr/lib/python3/dist-packages/click/core.py", line 1659, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/lib/python3/dist-packages/click/core.py", line 1659, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/lib/python3/dist-packages/click/core.py", line 1395, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/lib/python3/dist-packages/click/core.py", line 754, in invoke
    return __callback(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/click/decorators.py", line 84, in new_func
    return ctx.invoke(f, obj, *args, **kwargs)
  File "/usr/lib/python3/dist-packages/click/core.py", line 754, in invoke
    return __callback(*args, **kwargs)
  File "/home/ramrom/.local/lib/python3.10/site-packages/homeassistant_cli/plugins/state.py", line 288, in history
    start_time = dateparser.parse(since, settings=settings)
  File "/home/ramrom/.local/lib/python3.10/site-packages/dateparser/conf.py", line 85, in wrapper
    return f(*args, **kwargs)
  File "/home/ramrom/.local/lib/python3.10/site-packages/dateparser/__init__.py", line 53, in parse
    data = parser.get_date_data(date_string, date_formats)
  File "/home/ramrom/.local/lib/python3.10/site-packages/dateparser/date.py", line 417, in get_date_data
    parsed_date = _DateLocaleParser.parse(
  File "/home/ramrom/.local/lib/python3.10/site-packages/dateparser/date.py", line 194, in parse
    return instance._parse()
  File "/home/ramrom/.local/lib/python3.10/site-packages/dateparser/date.py", line 198, in _parse
    date_obj = self._parsers[parser_name]()
  File "/home/ramrom/.local/lib/python3.10/site-packages/dateparser/date.py", line 212, in _try_freshness_parser
    return freshness_date_parser.get_date_data(self._get_translated_date(), self._settings)
  File "/home/ramrom/.local/lib/python3.10/site-packages/dateparser/date.py", line 261, in _get_translated_date
    self._translated_date = self.locale.translate(
  File "/home/ramrom/.local/lib/python3.10/site-packages/dateparser/languages/locale.py", line 135, in translate
    relative_translations = self._get_relative_translations(settings=settings)
  File "/home/ramrom/.local/lib/python3.10/site-packages/dateparser/languages/locale.py", line 164, in _get_relative_translations
    self._generate_relative_translations(normalize=True))
  File "/home/ramrom/.local/lib/python3.10/site-packages/dateparser/languages/locale.py", line 178, in _generate_relative_translations
    pattern = DIGIT_GROUP_PATTERN.sub(r'?P<n>\d+', pattern)
  File "/home/ramrom/.local/lib/python3.10/site-packages/regex/regex.py", line 710, in _compile_replacement_helper
    is_group, items = _compile_replacement(source, pattern, is_unicode)
  File "/home/ramrom/.local/lib/python3.10/site-packages/regex/_regex_core.py", line 1737, in _compile_replacement
    raise error("bad escape \\%s" % ch, source.string, source.pos)
regex._regex_core.error: bad escape \d at position 7

I've had no issues running basically any other command (the tool is great!).


hass-cli version: 0.9.4
hass core version: 2022.12.1

@lolorc
Copy link

lolorc commented Mar 16, 2023

same here :
hass-cli version: 0.9.6
hass core version: 2023.03.04
python 3.10.6 & 3.9.2

@johntdyer
Copy link

same issue here too

hass-cli -x state history --since 50m  binary_sensor.fp1_home_office_occupancy
bad escape \d at position 7
Traceback (most recent call last):
  File "/opt/homebrew/Cellar/homeassistant-cli/0.9.6/libexec/lib/python3.11/site-packages/homeassistant_cli/cli.py", line 40, in run
    result = cli.main(standalone_mode=False)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/homeassistant-cli/0.9.6/libexec/lib/python3.11/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/homeassistant-cli/0.9.6/libexec/lib/python3.11/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/homeassistant-cli/0.9.6/libexec/lib/python3.11/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/homeassistant-cli/0.9.6/libexec/lib/python3.11/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/homeassistant-cli/0.9.6/libexec/lib/python3.11/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/homeassistant-cli/0.9.6/libexec/lib/python3.11/site-packages/click/decorators.py", line 84, in new_func
    return ctx.invoke(f, obj, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/homeassistant-cli/0.9.6/libexec/lib/python3.11/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/homeassistant-cli/0.9.6/libexec/lib/python3.11/site-packages/homeassistant_cli/plugins/state.py", line 288, in history
    start_time = dateparser.parse(since, settings=settings)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/homeassistant-cli/0.9.6/libexec/lib/python3.11/site-packages/dateparser/conf.py", line 85, in wrapper
    return f(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/homeassistant-cli/0.9.6/libexec/lib/python3.11/site-packages/dateparser/__init__.py", line 53, in parse
    data = parser.get_date_data(date_string, date_formats)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/homeassistant-cli/0.9.6/libexec/lib/python3.11/site-packages/dateparser/date.py", line 417, in get_date_data
    parsed_date = _DateLocaleParser.parse(
                  ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/homeassistant-cli/0.9.6/libexec/lib/python3.11/site-packages/dateparser/date.py", line 194, in parse
    return instance._parse()
           ^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/homeassistant-cli/0.9.6/libexec/lib/python3.11/site-packages/dateparser/date.py", line 198, in _parse
    date_obj = self._parsers[parser_name]()
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/homeassistant-cli/0.9.6/libexec/lib/python3.11/site-packages/dateparser/date.py", line 212, in _try_freshness_parser
    return freshness_date_parser.get_date_data(self._get_translated_date(), self._settings)
                                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/homeassistant-cli/0.9.6/libexec/lib/python3.11/site-packages/dateparser/date.py", line 261, in _get_translated_date
    self._translated_date = self.locale.translate(
                            ^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/homeassistant-cli/0.9.6/libexec/lib/python3.11/site-packages/dateparser/languages/locale.py", line 135, in translate
    relative_translations = self._get_relative_translations(settings=settings)
                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/homeassistant-cli/0.9.6/libexec/lib/python3.11/site-packages/dateparser/languages/locale.py", line 164, in _get_relative_translations
    self._generate_relative_translations(normalize=True))
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/homeassistant-cli/0.9.6/libexec/lib/python3.11/site-packages/dateparser/languages/locale.py", line 178, in _generate_relative_translations
    pattern = DIGIT_GROUP_PATTERN.sub(r'?P<n>\d+', pattern)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/homeassistant-cli/0.9.6/libexec/lib/python3.11/site-packages/regex/regex.py", line 710, in _compile_replacement_helper
    is_group, items = _compile_replacement(source, pattern, is_unicode)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/homeassistant-cli/0.9.6/libexec/lib/python3.11/site-packages/regex/_regex_core.py", line 1737, in _compile_replacement
    raise error("bad escape \\%s" % ch, source.string, source.pos)
regex._regex_core.error: bad escape \d at position 7

@johanbaaij
Copy link

If you installed with homebrew: The following worked for me, for now...

pip install --upgrade --target /opt/homebrew/lib/python3.11/site-packages/ dateparser

@stbuerger
Copy link

Has someone found out more on this ?

Still same error on hass-cli version: 0.9.7 when invoked like
hass-cli state history --since 360m sensor.esphome_web_d43035_gasverbrauch
or any other way of hass-cli state history ENTITY

@johntdyer
Copy link

ok, so I figured it out ... the websocket response to to large for the default max of the library... I've put together a PR here but I am having trouble getting the tests to pass... If you want to install my branch you will just need to add an env var to increase the max websocket response. The default seems to be 4mb and I got it working when I went to 5mb

@leo-b
Copy link

leo-b commented Dec 27, 2023

$ hass-cli state history sun.sun
error: error: bad escape \d at position 7

This is because of some regex behavior change introduced in regex 2022.3.15, which breaks dateparser:
scrapinghub/dateparser#1045

dateparser >= 1.1.4 should be fixed but unfortunately homeassistant-cli locks dateparser at (>=0.7.1,<0.8):
https://github.com/home-assistant-ecosystem/home-assistant-cli/blob/0.9.6/setup.py#L85

The dev-Branch lifts that restriction but unfortunately there is no released version yet.

@johntdyer
Copy link

@leo-b odd... I'm curious how my max payload size fix for websockets was able to get around this issue then? I ask because I've been using my fork for a while now with zero reocurance of the issue since my "fix" .... Possible we might have been having similar but different issues?

@brandonleon
Copy link

On macOS, if you install via pipx (pipx install homeassistant-cli), you can inject a new version of dateparser with pipx inject homeassistant-cli dateparser==1.2.0.

@varenc
Copy link

varenc commented Apr 19, 2024

Just ran into the same issue. homeassistant-cli seems to have an incorrect requirement on the dateparser version be dateparser<0.8,>=0.7.1. But forcibly using a newer version of dateparser works fine. I fixed it by doing this:

$ pip3 uninstall dateparser -y
$ pip install "dateparser>=1.2.0"

Edit: it seems that this d4e2312 commit fixed the incorrect dateparser version requirement. However, there hasn't been a release of homeassistant-cli since that commit. So just installing the HEAD version will probably fix it. (probably time to do another release)

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

8 participants