[GH-ISSUE #1144] [BUG] results.py💯 SyntaxWarning: invalid escape sequence '\|' #695

Closed
opened 2026-02-25 20:36:19 +03:00 by kerem · 1 comment
Owner

Originally created by @ghost on GitHub (Apr 27, 2024).
Original GitHub issue: https://github.com/benbusby/whoogle-search/issues/1144

Describe the bug
Getting the below warning on Arch Linux with Python 3.12:

Apr 27 18:53:23 lab16 whoogle[4699: /home/glitsj16/whoogle-search/app/utils/results.py:100: SyntaxWarning: invalid escape sequence '\|'
Apr 27 18:53:23 lab16 whoogle[4699:   if re.match('.*[@_!#$%^&*()<>?/\|}{~:].*', target_word) or (

To Reproduce
Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Deployment Method

  • Heroku (one-click deploy)
  • Docker
  • [x ] run executable
  • pip/pipx
  • Other: [describe setup]

Version of Whoogle Search

  • [ x] Latest build from [source] (i.e. GitHub, Docker Hub, pip, etc)
  • Version [version number]
  • Not sure

Desktop (please complete the following information):

  • OS: Arch Linux
  • Browser Firefox
  • Version 125.0.2-1

Smartphone (please complete the following information):

  • Device: N/A
  • OS: N/A
  • Browser N/A
  • Version N/A

Additional context
Add any other context about the problem here.

$ pacman -Q python
python 3.12.3-1

This small patch fixes the warning for me, but this is python 3.12 so there's probably a better way to deal with the warning:

UPDATE:
This is due to the fact that Python 3.12.3 does SyntaxWarning instead of DeprecationWarning for invalid backslash escape sequences:

Invalid backslash escape sequences in strings now warn with SyntaxWarning instead of DeprecationWarning, making them more visible. (They will become syntax errors in the future.)

Using a raw string for matching regex fixes things:

$ cat syntaxwarning.patch
--- a/app/utils/results.py
+++ b/app/utils/results.py
@@ -97,7 +97,7 @@
         else:
             reg_pattern = fr'\b((?![{{}}<>-]){target_word}(?![{{}}<>-]))\b'
 
-        if re.match('.*[@_!#$%^&*()<>?/\|}{~:].*', target_word) or (
+        if re.match(r'.*[@_!#$%^&*()<>?/\|}{~:].*', target_word) or (
                 element.parent and element.parent.name == 'style'):
             return

HTH

Originally created by @ghost on GitHub (Apr 27, 2024). Original GitHub issue: https://github.com/benbusby/whoogle-search/issues/1144 **Describe the bug** Getting the below warning on Arch Linux with Python 3.12: ```console Apr 27 18:53:23 lab16 whoogle[4699: /home/glitsj16/whoogle-search/app/utils/results.py:100: SyntaxWarning: invalid escape sequence '\|' Apr 27 18:53:23 lab16 whoogle[4699: if re.match('.*[@_!#$%^&*()<>?/\|}{~:].*', target_word) or ( ``` **To Reproduce** Steps to reproduce the behavior: 1. Go to '...' 2. Click on '....' 3. Scroll down to '....' 4. See error **Deployment Method** - [ ] Heroku (one-click deploy) - [ ] Docker - [x ] `run` executable - [ ] pip/pipx - [ ] Other: [describe setup] **Version of Whoogle Search** - [ x] Latest build from [source] (i.e. GitHub, Docker Hub, pip, etc) - [ ] Version [version number] - [ ] Not sure **Desktop (please complete the following information):** - OS: Arch Linux - Browser Firefox - Version 125.0.2-1 **Smartphone (please complete the following information):** - Device: N/A - OS: N/A - Browser N/A - Version N/A **Additional context** Add any other context about the problem here. $ pacman -Q python python 3.12.3-1 ~~This small patch fixes the warning for me, but this is `python 3.12` so there's probably a better way to deal with the warning:~~ UPDATE: This is due to the fact that [Python 3.12.3](https://www.python.org/downloads/release/python-3123/) does SyntaxWarning instead of DeprecationWarning for invalid backslash escape sequences: > Invalid backslash escape sequences in strings now warn with SyntaxWarning instead of DeprecationWarning, making them more visible. (They will become syntax errors in the future.) Using a `raw` string for matching regex fixes things: ```console $ cat syntaxwarning.patch --- a/app/utils/results.py +++ b/app/utils/results.py @@ -97,7 +97,7 @@ else: reg_pattern = fr'\b((?![{{}}<>-]){target_word}(?![{{}}<>-]))\b' - if re.match('.*[@_!#$%^&*()<>?/\|}{~:].*', target_word) or ( + if re.match(r'.*[@_!#$%^&*()<>?/\|}{~:].*', target_word) or ( element.parent and element.parent.name == 'style'): return ``` HTH
kerem 2026-02-25 20:36:19 +03:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@davidthewatson commented on GitHub (Aug 27, 2024):

Confirmed fix on Garuda Linux with whoogle installed via AUR.

Before patch:

     ╭─watson@acer in /opt/whoogle-search via  v3.12.5 (venv) as 🧙 took 15ms
     ╰─λ ./run 
    Running on http://0.0.0.0:5000
    /opt/whoogle-search/app/utils/results.py:100: SyntaxWarning: invalid escape sequence '\|'
      if re.match('.*[@_!#$%^&*()<>?/\|}{~:].*', target_word) or (
    Exception in thread Thread-1 (gen_bangs_json):
    Traceback (most recent call last):
      File "/usr/lib/python3.12/threading.py", line 1075, in _bootstrap_inner
        self.run()
      File "/usr/lib/python3.12/threading.py", line 1012, in run
        self._target(*self._args, **self._kwargs)
      File "/opt/whoogle-search/app/utils/bangs.py", line 26, in gen_bangs_json
        data = json.loads(r.text)
               ^^^^^^^^^^^^^^^^^^
      File "/usr/lib/python3.12/json/__init__.py", line 346, in loads
        return _default_decoder.decode(s)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/usr/lib/python3.12/json/decoder.py", line 337, in decode
        obj, end = self.raw_decode(s, idx=_w(s, 0).end())
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/usr/lib/python3.12/json/decoder.py", line 355, in raw_decode
        raise JSONDecodeError("Expecting value", s, err.value) from None
    json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
    t/whoogle-search/app/utils/results.py:100: SyntaxWarning: invalid escape sequence '\|'
      if re.match('.*[@_!#$%^&*()<>?/\|}{~:].*', target_word) or (
    Exception in thread Thread-1 (gen_bangs_json):
    Traceback (most recent call last):
      File "/usr/lib/python3.12/threading.py", line 1075, in _bootstrap_inner
        self.run()
      File "/usr/lib/python3.12/threading.py", line 1012, in run
        self._target(*self._args, **self._kwargs)
      File "/opt/whoogle-search/app/utils/bangs.py", line 26, in gen_bangs_json
        data = json.loads(r.text)
               ^^^^^^^^^^^^^^^^^^
      File "/usr/lib/python3.12/json/__init__.py", line 346, in loads
        return _default_decoder.decode(s)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/usr/lib/python3.12/json/decoder.py", line 337, in decode
        obj, end = self.raw_decode(s, idx=_w(s, 0).end())
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/usr/lib/python3.12/json/decoder.py", line 355, in raw_decode
        raise JSONDecodeError("Expecting value", s, err.value) from None
    json.decoder.JSONDecodeError: Expecting value: lin
    ^C⏎                                                                                         

After patch:

     ╭─watson@acer in /opt/whoogle-search via  v3.12.5 (venv) as 🧙 took 1m58s
     ╰─λ ./run
    Running on http://0.0.0.0:5000
    ^C⏎                                 

Version:

     ╭─watson@acer in /opt/whoogle-search via  v3.12.5 (venv) as 🧙 took 231ms
     ╰─λ pamac search whoogle
    whoogle  0.8.4-1.1 [Installed]                                                   chaotic-aur
        A self-hosted, ad-free, privacy-respecting metasearch engine

Thanks for the fix!

<!-- gh-comment-id:2312941451 --> @davidthewatson commented on GitHub (Aug 27, 2024): Confirmed fix on Garuda Linux with whoogle installed via AUR. Before patch: ╭─watson@acer in /opt/whoogle-search via  v3.12.5 (venv) as 🧙 took 15ms ╰─λ ./run Running on http://0.0.0.0:5000 /opt/whoogle-search/app/utils/results.py:100: SyntaxWarning: invalid escape sequence '\|' if re.match('.*[@_!#$%^&*()<>?/\|}{~:].*', target_word) or ( Exception in thread Thread-1 (gen_bangs_json): Traceback (most recent call last): File "/usr/lib/python3.12/threading.py", line 1075, in _bootstrap_inner self.run() File "/usr/lib/python3.12/threading.py", line 1012, in run self._target(*self._args, **self._kwargs) File "/opt/whoogle-search/app/utils/bangs.py", line 26, in gen_bangs_json data = json.loads(r.text) ^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.12/json/__init__.py", line 346, in loads return _default_decoder.decode(s) ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.12/json/decoder.py", line 337, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.12/json/decoder.py", line 355, in raw_decode raise JSONDecodeError("Expecting value", s, err.value) from None json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0) t/whoogle-search/app/utils/results.py:100: SyntaxWarning: invalid escape sequence '\|' if re.match('.*[@_!#$%^&*()<>?/\|}{~:].*', target_word) or ( Exception in thread Thread-1 (gen_bangs_json): Traceback (most recent call last): File "/usr/lib/python3.12/threading.py", line 1075, in _bootstrap_inner self.run() File "/usr/lib/python3.12/threading.py", line 1012, in run self._target(*self._args, **self._kwargs) File "/opt/whoogle-search/app/utils/bangs.py", line 26, in gen_bangs_json data = json.loads(r.text) ^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.12/json/__init__.py", line 346, in loads return _default_decoder.decode(s) ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.12/json/decoder.py", line 337, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.12/json/decoder.py", line 355, in raw_decode raise JSONDecodeError("Expecting value", s, err.value) from None json.decoder.JSONDecodeError: Expecting value: lin ^C⏎ After patch: ╭─watson@acer in /opt/whoogle-search via  v3.12.5 (venv) as 🧙 took 1m58s ╰─λ ./run Running on http://0.0.0.0:5000 ^C⏎ Version: ╭─watson@acer in /opt/whoogle-search via  v3.12.5 (venv) as 🧙 took 231ms ╰─λ pamac search whoogle whoogle 0.8.4-1.1 [Installed] chaotic-aur A self-hosted, ad-free, privacy-respecting metasearch engine Thanks for the fix!
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/whoogle-search#695
No description provided.