Skip to content
This repository has been archived by the owner on Sep 7, 2023. It is now read-only.

Replace requests with httpx #2800

Merged
merged 7 commits into from May 3, 2021
Merged

Replace requests with httpx #2800

merged 7 commits into from May 3, 2021

Conversation

kvch
Copy link
Member

@kvch kvch commented May 3, 2021

What does this PR do?

This PR adds httpx to searx. This is the continuation of #2727 cherry-picked from searxng.

Why is this change important?

Speeds up searx. \o/

I just opened the PR to run tests before merging. Locally everything seems fine.

dalf and others added 7 commits May 3, 2021 21:39
patch engine initialization to skip HTTP request
(engine_init function in searx.engines.initialize_engines)
settings.yml:

* outgoing.networks:
   * can contains network definition
   * propertiers: enable_http, verify, http2, max_connections, max_keepalive_connections,
     keepalive_expiry, local_addresses, support_ipv4, support_ipv6, proxies, max_redirects, retries
   * retries: 0 by default, number of times searx retries to send the HTTP request (using different IP & proxy each time)
   * local_addresses can be "192.168.0.1/24" (it supports IPv6)
   * support_ipv4 & support_ipv6: both True by default
     see searx#1034
* each engine can define a "network" section:
   * either a full network description
   * either reference an existing network

* all HTTP requests of engine use the same HTTP configuration (it was not the case before, see proxy configuration in master)
The issue exists only in the debug log::

     --- Logging error ---
     Traceback (most recent call last):
       File "/usr/lib/python3.9/logging/__init__.py", line 1086, in emit
	 stream.write(msg + self.terminator)
     UnicodeEncodeError: 'ascii' codec can't encode characters in position 79-89: ordinal not in range(128)
     Call stack:
       File "/usr/local/searx/searx-pyenv/lib/python3.9/site-packages/flask/app.py", line 2464, in __call__
	 return self.wsgi_app(environ, start_response)
       File "/usr/local/searx/searx-src/searx/webapp.py", line 1316, in __call__
	 return self.app(environ, start_response)
       File "/usr/local/searx/searx-pyenv/lib/python3.9/site-packages/werkzeug/middleware/proxy_fix.py", line 169, in __call__
	 return self.app(environ, start_response)
       File "/usr/local/searx/searx-pyenv/lib/python3.9/site-packages/flask/app.py", line 2447, in wsgi_app
	 response = self.full_dispatch_request()
       File "/usr/local/searx/searx-pyenv/lib/python3.9/site-packages/flask/app.py", line 1950, in full_dispatch_request
	 rv = self.dispatch_request()
       File "/usr/local/searx/searx-pyenv/lib/python3.9/site-packages/flask/app.py", line 1936, in dispatch_request
	 return self.view_functions[rule.endpoint](**req.view_args)
       File "/usr/local/searx/searx-src/searx/webapp.py", line 766, in search
	 number_of_results=format_decimal(number_of_results),
       File "/usr/local/searx/searx-pyenv/lib/python3.9/site-packages/flask_babel/__init__.py", line 458, in format_decimal
	 locale = get_locale()
       File "/usr/local/searx/searx-pyenv/lib/python3.9/site-packages/flask_babel/__init__.py", line 226, in get_locale
	 rv = babel.locale_selector_func()
       File "/usr/local/searx/searx-src/searx/webapp.py", line 249, in get_locale
	 logger.debug("%s uses locale `%s` from %s", request.url, locale, locale_source)
     Unable to print the message and arguments - possible formatting error.
     Use the traceback above to help find the error.

Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
Requirement idna was added in 181c12a but I don't know why.  This package
is not directly used by searxng but its a sub-requirement of some other packages
using package `requests` (with different range of supported versions, see
below).  In summary one can say: the version of idna should be depend on package
`requests`::

    ...
    Pallets-Sphinx-Themes==1.2.3
      ...
      - Sphinx [required: Any, installed: 3.5.4]
        ...
        - requests [required: >=2.5.0, installed: 2.25.1]
	  ...
          - idna [required: >=2.5,<3, installed: 2.10]
        ...
    ...
    transifex-client==0.14.2
      - requests [required: >=2.19.1,<3.0.0, installed: 2.25.1]
        ...
        - idna [required: >=2.5,<3, installed: 2.10]
    twine==3.4.1
      ...
      - requests [required: >=2.20, installed: 2.25.1]
        ...
        - idna [required: >=2.5,<3, installed: 2.10]

Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
* searx.network.client.LOOP is initialized in a thread
* searx.network.__init__ imports LOOP which may happen
  before the thread has initialized LOOP

This commit adds a new function "searx.network.client.get_loop()"
to fix this issue
@kvch kvch merged commit d93ac96 into searx:master May 3, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants