这是indexloc提供的服务,不要输入任何密码
Skip to content

Conversation

@return42
Copy link
Member

@return42 return42 commented Jul 5, 2022

What does this PR do?

Tineye: handle 422 response of not supported img format

grafik

Related issues

Closes: #1449

@return42 return42 requested a review from dalf July 5, 2022 20:09
@return42 return42 mentioned this pull request Jul 6, 2022
@dalf
Copy link
Contributor

dalf commented Jul 8, 2022

I've tried various URL, here two examples:

  • https://i.ytimg.com/an_webp/gusXBTyg1O4/mqdefault_6s.webp?du=3000&sqp=CNjCn5YG&rs=AOn4CLBNM0alsGkVAM7rKJ5CydtKcVY2kQ
    • suggestions.key: "Too Simple"
    • Status Code: 400
  • https://tineye.com/result_json
    • suggestions.key: "Download Error"
    • Status Code: 422

Looking at tineye PIP package, it seems the result is always a JSON: https://github.com/TinEye/pytineye/blob/d51c637a4b3e9b50b47739b540ab908243bf4f91/pytineye/api.py#L277 (Note: the entry point is different, we can't be sure)

So, the following code deals with more situation:

    if resp.is_error:
        # handle error codes from Tineye
        if resp.status_code in (400, 422):
            error = json_data.get('error')
            s_key = json_data.get('suggestions', {}).get('key', '')
            if s_key.startswith("Invalid image URL"):
                message = format_not_supported
            elif s_key:
                message = "TinEye:" + s_key
            else:
                message =  "TinEye:" + error
            results.append({'answer': message})
            return results
        resp.raise_for_status()

I feel we divert the usage of the answers or there are some missing features: looking at the code, we need to specify the engine name because the answers don't provide the engine.
The result is more an error, except we don't provide a way to return that.

For now:

  • I would just return an empty result
  • open an issue to allow engine to return usage error.
  • once implemented, we can update tineye.py

Out of topic: when I've search for the query https://tineye.com/result_json python, tineye got the query and returned an error. We can avoid this if we

  • move tineye to the images category.
  • match only full URL without space.
  • provide a category for URL search: !url https://example.com

@return42
Copy link
Member Author

return42 commented Jul 23, 2022

For now:

  • I would just return an empty result
  • open an issue to allow engine to return usage error.

first lets merge #1412

  • once implemented, we can update tineye.py

OK

  • provide a category for URL search: !url https://example.com

No need for, it is a online_url_search engine:

re_search_urls = {
'http': re.compile(r'https?:\/\/[^ ]*'),
'ftp': re.compile(r'ftps?:\/\/[^ ]*'),
'data:image': re.compile('data:image/[^; ]*;base64,[^ ]*'),
}

when I've search for the query https://tineye.com/result_json python, tineye got the query and returned an error.

The https://tineye.com/result_json URL is responsible for the error / its not an image URL.

@return42 return42 force-pushed the fix-1449 branch 2 times, most recently from 84b99ee to 873e7e1 Compare July 23, 2022 13:32
Closes: searxng#1449
Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
@return42 return42 merged commit 39d0156 into searxng:master Jul 23, 2022
@return42 return42 deleted the fix-1449 branch July 23, 2022 14:05
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.

Bug: tineye engine

2 participants