Skip to content

Conversation

@Aadniz
Copy link
Contributor

@Aadniz Aadniz commented Nov 13, 2025

What does this PR do?

Ahmia recently implemented a 60 minute rotating token system when searching. If these tokens are not provided, it will redirect to the homepage, and SearXNG returning a parsing error.
The tokens update every minute, but Ahmia allow up to 1 hour old tokens to be used.

This implementation gets the keys from the hidden input using xpaths, and uses the EngineCache to prevent having to do 2 requests on every search. It will however search 2 times for the first initial request towards Ahmia, and also if tokens are older than 1 hour.

I took inspiration from semantic scholar engine to set up the cache.

Why is this change important?

As of now, SearXNG will return a parsing error when trying to search Ahmia because it is returning a redirect to the homepage.

There is also very few tor-specific search engines on SearXNG, and feel it is important that this works.

How to test this PR locally?

  1. Clone this PR
  2. Set up tor socks proxy (usually it's on port 9050)
  3. Use the following settings in settings.yml:
categories_as_tabs:
  general:
  images:
  videos:
  news:
  map:
  music:
  it:
  science:
  files:
  social media:
  onions:
  
engines:
  - name: ahmia
    using_tor_proxy: true
    proxies:
      all://:
        - socks5h://127.0.0.1:9050
  1. Start SearXNG
  2. Search for !ah test for example

Ahmia recently implemented a 60 minute rotating token system when searching.

This fix uses the cache and updates the tokens on every request.
Copy link
Member

@Bnyro Bnyro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm always running into a ReplyError of the proxy after the timeout period of SearXNG is finished (even set it to 10 seconds), so probably something wrong on my configuration. (I simply ran tor and used the address it told me to use 🤷)

PS: Not related to your changes, but in case of a proxy error it crashes with

  File "/home/username/Projects/searxng/searx/network/client.py", line 111, in handle_async_request
    raise httpx.ProxyError("ProxyError: " + e.args[0], request=request) from e
                           ~~~~~~~~~~~~~~~^~~~~~~~~~~
TypeError: can only concatenate str (not "ReplyError") to str

instead of actually displaying the proxy error

@Aadniz
Copy link
Contributor Author

Aadniz commented Nov 20, 2025

I want to test a bit more before coming back to this. It seems to be very slow, often just times out and it sometimes gives the proxy error as you mentioned that can be hard to reproduce sometimes.

@Aadniz
Copy link
Contributor Author

Aadniz commented Dec 12, 2025

I'm always running into a ReplyError of the proxy after the timeout period of SearXNG is finished (even set it to 10 seconds), so probably something wrong on my configuration. (I simply ran tor and used the address it told me to use 🤷)

@Bnyro It could be that it differs from distro to distro. You can test if the tor proxy is working by running curl --proxy socks5h://127.0.0.1:9050 ipaddr.me, or confirm it here by reading through the HTML output: curl --proxy socks5h://127.0.0.1:9050 https://check.torproject.org/. On Debian, the tor socks config is located at /etc/tor/torsocks.conf

@Aadniz
Copy link
Contributor Author

Aadniz commented Dec 12, 2025

Although it is incredible slow, I cannot think of a better solution. The nature of the tor network is just slow afterall, and having to spend two requests sometimes does not make it better.

I believe those who are interested in running tor-related engines on their SearXNG instances, are willing to accept how slow it is. I recommend setting up the timeout for Ahmia to 20 seconds.

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

Successfully merging this pull request may close these issues.

2 participants