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

[BUG] 500 Internal Server Error #1050

Closed
2 of 8 tasks
seirdotexe opened this issue Aug 10, 2023 · 1 comment · Fixed by #1052
Closed
2 of 8 tasks

[BUG] 500 Internal Server Error #1050

seirdotexe opened this issue Aug 10, 2023 · 1 comment · Fixed by #1052
Labels
bug Something isn't working

Comments

@seirdotexe
Copy link

Describe the bug
When you search for Mathias Normann, you get error code 500. It doesn't happen when you search for Mathias Normannaaa.

To Reproduce
Steps to reproduce the behavior:

  1. Search on your Whoogle instance for Mathias Normann.

Deployment Method

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

Version of Whoogle Search

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

Desktop (please complete the following information):

  • OS: Windows 11 Pro
  • Browser: FireFox Developer Edition
  • Version 117.0b5 (64-bit)

Additional context

08/10/2023 4:21:21 PM
ERROR:app:Exception on /search [POST]
08/10/2023 4:21:21 PM
Traceback (most recent call last):
08/10/2023 4:21:21 PM
  File "/usr/local/lib/python3.11/site-packages/flask/app.py", line 2190, in wsgi_app
08/10/2023 4:21:21 PM
    response = self.full_dispatch_request()
08/10/2023 4:21:21 PM
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
08/10/2023 4:21:21 PM
  File "/usr/local/lib/python3.11/site-packages/flask/app.py", line 1486, in full_dispatch_request
08/10/2023 4:21:21 PM
    rv = self.handle_user_exception(e)
08/10/2023 4:21:21 PM
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
08/10/2023 4:21:21 PM
  File "/usr/local/lib/python3.11/site-packages/flask/app.py", line 1484, in full_dispatch_request
08/10/2023 4:21:21 PM
    rv = self.dispatch_request()
08/10/2023 4:21:21 PM
         ^^^^^^^^^^^^^^^^^^^^^^^
08/10/2023 4:21:21 PM
  File "/usr/local/lib/python3.11/site-packages/flask/app.py", line 1469, in dispatch_request
08/10/2023 4:21:21 PM
    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
08/10/2023 4:21:21 PM
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
08/10/2023 4:21:21 PM
  File "/whoogle/app/routes.py", line 122, in decorated
08/10/2023 4:21:21 PM
    return f(*args, **kwargs)
08/10/2023 4:21:21 PM
           ^^^^^^^^^^^^^^^^^^
08/10/2023 4:21:21 PM
  File "/whoogle/app/routes.py", line 57, in decorated
08/10/2023 4:21:21 PM
    return f(*args, **kwargs)
08/10/2023 4:21:21 PM
           ^^^^^^^^^^^^^^^^^^
08/10/2023 4:21:21 PM
  File "/whoogle/app/routes.py", line 314, in search
08/10/2023 4:21:21 PM
    response = search_util.generate_response()
08/10/2023 4:21:21 PM
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
08/10/2023 4:21:21 PM
  File "/whoogle/app/utils/search.py", line 165, in generate_response
08/10/2023 4:21:21 PM
    formatted_results = content_filter.clean(html_soup)
08/10/2023 4:21:21 PM
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
08/10/2023 4:21:21 PM
  File "/whoogle/app/filter.py", line 170, in clean
08/10/2023 4:21:21 PM
    self.update_link(link)
08/10/2023 4:21:21 PM
    ^^^^^^^^^^^^^^^^^^^^^^
08/10/2023 4:21:21 PM
  File "/whoogle/app/filter.py", line 496, in update_link
08/10/2023 4:21:21 PM
    q = extract_q(result_link.query, href)
08/10/2023 4:21:21 PM
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
08/10/2023 4:21:21 PM
  File "/whoogle/app/filter.py", line 47, in extract_q
08/10/2023 4:21:21 PM
    return parse_qs(q_str)['q'][0] if ('&q=' in href or '?q=' in href) else ''
08/10/2023 4:21:21 PM
           ~~~~~~~~~~~~~~~^^^^^
08/10/2023 4:21:21 PM
KeyError: 'q'
@seirdotexe seirdotexe added the bug Something isn't working label Aug 10, 2023
@ahmad-alkadri
Copy link
Contributor

ahmad-alkadri commented Aug 13, 2023

Confirmed getting the same bug on my docker instance.

It seems that the problem's coming from the parsing of the query. Curious if there's other instances of search queries producing this bug.

EDIT: Found the problem. This function:

def extract_q(q_str: str, href: str) -> str:
"""Extracts the 'q' element from a result link. This is typically
either the link to a result's website, or a string.
Args:
q_str: The result link to parse
href: The full url to check for standalone 'q' elements first,
rather than parsing the whole query string and then checking.
Returns:
str: The 'q' element of the link, or an empty string
"""
return parse_qs(q_str)['q'][0] if ('&q=' in href or '?q=' in href) else ''

will return the first element of an array in ['q'] key of the result of the parse_qs function. The problem was there could be an instance where the value would be blank. And the parse_qs is from the urllib module, which is a built-in python module.

Luckily according to the doc of the function we could keep the blank value instead of throwing it. I'll try it and try to make a PR asap if successful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants