kitUIN/PicImageSearch

How to solve it?

LwB-l opened this issue · 7 comments

 DeprecationWarning: There is no current event loop
  loop = asyncio.get_event_loop()
2024-03-27 19:03:58.576 | INFO     | __main__:show_result:48 - ['https://www.google.co.jp/search?tbs=sbi:AMhZZivZTycvn-TYWekgq4YSrsxQ1b1-OlgmBWA-9xu8nU2ILP8NNNktK_1fF-jkXjTMF_11HQAH7CvMUd-GhLglA8Gq6_1flXmyG7RIv1LcwFoVTn2tueoDMvNJs-SDAR_1rUwuAVLwiheoVTSWFEJDqnXsS9t2ppA24-E4nIHdoHqf3dlMmqFOKMBcMVzP70DpxDFMb9Z6AJ9WUHP6oDqsZLWCwxCl2ja2HbL5-I3IU8N_1mQAlrQ5UZdbG91KLkSmxe7y3vFDY0FIFkK3c2icuR50OycPx3hvjoomMxwgPOAkaq0Za_1C478YMmC41JBjEKG1nerBCpNJ5u']
2024-03-27 19:03:58.576 | INFO     | __main__:show_result:49 - 1
2024-03-27 19:03:58.576 | INFO     | __main__:show_result:50 - https://www.google.co.jp/search?tbs=sbi:AMhZZivZTycvn-TYWekgq4YSrsxQ1b1-OlgmBWA-9xu8nU2ILP8NNNktK_1fF-jkXjTMF_11HQAH7CvMUd-GhLglA8Gq6_1flXmyG7RIv1LcwFoVTn2tueoDMvNJs-SDAR_1rUwuAVLwiheoVTSWFEJDqnXsS9t2ppA24-E4nIHdoHqf3dlMmqFOKMBcMVzP70DpxDFMb9Z6AJ9WUHP6oDqsZLWCwxCl2ja2HbL5-I3IU8N_1mQAlrQ5UZdbG91KLkSmxe7y3vFDY0FIFkK3c2icuR50OycPx3hvjoomMxwgPOAkaq0Za_1C478YMmC41JBjEKG1nerBCpNJ5u
2024-03-27 19:03:58.576 | INFO     | __main__:show_result:51 - 1
2024-03-27 19:03:58.578 | ERROR    | asyncio.events:_run:80 - An error has been caught in function '_run', process 'MainProcess' (4620), thread 'MainThread' (21300):
Traceback (most recent call last):

  File "D:\DrissionPage-dev\try.py", line 64, in <module>
    loop.run_until_complete(t1())
    │    │                  └ <function t1 at 0x000001DBB6389900>
    │    └ <function BaseEventLoop.run_until_complete at 0x000001DBB38BD240>
    └ <ProactorEventLoop running=True closed=False debug=False>

  File "F:\dev\Python\Python3.10.4\lib\asyncio\base_events.py", line 633, in run_until_complete
    self.run_forever()
    │    └ <function ProactorEventLoop.run_forever at 0x000001DBB3993640>
    └ <ProactorEventLoop running=True closed=False debug=False>

  File "F:\dev\Python\Python3.10.4\lib\asyncio\windows_events.py", line 321, in run_forever
    super().run_forever()

  File "F:\dev\Python\Python3.10.4\lib\asyncio\base_events.py", line 600, in run_forever
    self._run_once()
    │    └ <function BaseEventLoop._run_once at 0x000001DBB38BECB0>
    └ <ProactorEventLoop running=True closed=False debug=False>

  File "F:\dev\Python\Python3.10.4\lib\asyncio\base_events.py", line 1896, in _run_once
    handle._run()
    │      └ <function Handle._run at 0x000001DBB386A830>
    └ <Handle <TaskStepMethWrapper object at 0x000001DBB64380D0>()>

> File "F:\dev\Python\Python3.10.4\lib\asyncio\events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
    │    │            │    │           │    └ <member '_args' of 'Handle' objects>
    │    │            │    │           └ <Handle <TaskStepMethWrapper object at 0x000001DBB64380D0>()>
    │    │            │    └ <member '_callback' of 'Handle' objects>
    │    │            └ <Handle <TaskStepMethWrapper object at 0x000001DBB64380D0>()>
    │    └ <member '_context' of 'Handle' objects>
    └ <Handle <TaskStepMethWrapper object at 0x000001DBB64380D0>()>

  File "D:\DrissionPage-dev\try.py", line 23, in t1
    show_result(resp)
    │           └ <PicImageSearch.model.google.GoogleResponse object at 0x000001DBB3D2D870>
    └ <function show_result at 0x000001DBB6389CF0>

  File "D:\DrissionPage-dev\try.py", line 54, in show_result
    selected = next((i for i in resp.raw if i.thumbnail), resp.raw[0])
                                │    │                    │    └ []
                                │    │                    └ <PicImageSearch.model.google.GoogleResponse object at 0x000001DBB3D2D870>
                                │    └ []
                                └ <PicImageSearch.model.google.GoogleResponse object at 0x000001DBB3D2D870>

IndexError: list index out of range

The log output you provided seems quite clear, doesn't it?
The issue arises because the returned result resp.raw is an empty list, which leads to resp.raw[0] being inaccessible and thus triggers an IndexError.

But in fact, it does not return the result of searching for images, but an error page. Maybe the example or Google's original code is wrong.

That seems to be an issue on your end.It might be related to your network environment.
I've tested the Google link from the log output you provided and it appears to be working properly on my end.
Here is my log output:

2024-03-27 13:36:45.492 | INFO     | __main__:show_result:48 - ['https://www.google.co.jp/search?tbs=sbi:AMhZZitSyTX0x9LcLR1f1hVLx_1LEdGIPfcHMnSl87VHaSrnUssA-I-f2yEQL-zzdju-v-NLFDxXQt1uPgUTLbqe4yj0TjSThTzKf5Sp4rcyepe9yg7RPPIJHAlN8NE1mH8pnHN7wRVVqYfeEfjK1N4Egk1yh8mF1IzFGf-nNXsHFG80MozRae2Sh1CXAhHy0VtQ5aKWf9LppZCLwFN9QTNV-FHNDJbwZHKeMBrw-hCaql3ksquaxevt8R9BmMCL_1QfGS2M5jI3XUw4xZISxf6fNgZwfqhwPTs6RrAE7QTHj1cLGPne5sQxGphgNEbsrwKfLt507VFNOOLaEZMylA9lEY_10KLBkHtcQ']
2024-03-27 13:36:45.492 | INFO     | __main__:show_result:49 - 1
2024-03-27 13:36:45.493 | INFO     | __main__:show_result:50 - https://www.google.co.jp/search?tbs=sbi:AMhZZitSyTX0x9LcLR1f1hVLx_1LEdGIPfcHMnSl87VHaSrnUssA-I-f2yEQL-zzdju-v-NLFDxXQt1uPgUTLbqe4yj0TjSThTzKf5Sp4rcyepe9yg7RPPIJHAlN8NE1mH8pnHN7wRVVqYfeEfjK1N4Egk1yh8mF1IzFGf-nNXsHFG80MozRae2Sh1CXAhHy0VtQ5aKWf9LppZCLwFN9QTNV-FHNDJbwZHKeMBrw-hCaql3ksquaxevt8R9BmMCL_1QfGS2M5jI3XUw4xZISxf6fNgZwfqhwPTs6RrAE7QTHj1cLGPne5sQxGphgNEbsrwKfLt507VFNOOLaEZMylA9lEY_10KLBkHtcQ
2024-03-27 13:36:45.493 | INFO     | __main__:show_result:51 - 1
2024-03-27 13:36:45.493 | INFO     | __main__:show_result:55 - <div jscontroller="SC7lYd" class="g Ww4FFb vt6azd tF2Cxc asEBEc" lang="zh-CN" style="width:652px" jsaction="QyLbLe:OMITjf;ewaord:qsYrDe;xd28Mb:A6j43c" data-hveid="CBAQAA" data-ved="2ahUKEwjkw4T7x5SFAxX_O0QIHYe2AOoQFSgAegQIEBAA"><div class="srKDX cvP2Ce" data-snc="PHrob"><div class="kb0PBd cvP2Ce ieodic jGGQ5e" style="grid-area:x5WNvb" data-snf="x5WNvb" data-snhf="0"><div class="yuRUbf"><div><span jscontroller="msmzHf" jsaction="rcuQ6b:npT2md;PYDNKe:bLV6Bd;mLt3mc"><a jsname="UWckNb" href="https://sg.world.taobao.com/item/661630071666.htm" data-ved="2ahUKEwjkw4T7x5SFAxX_O0QIHYe2AOoQFnoECAoQAQ" ping="/url?sa=t&amp;source=web&amp;rct=j&amp;opi=89978449&amp;url=https://sg.world.taobao.com/item/661630071666.htm&amp;ved=2ahUKEwjkw4T7x5SFAxX_O0QIHYe2AOoQFnoECAoQAQ"><br/><h3 class="LC20lb MBeuO DKV0Md">放学后的制服馆/承熙高校/jk格裙毛衣背心马甲针织女半身短裙 ...</h3><div class="notranslate HGLrXd NJjxre iUh30 ojE3Fb"><div class="q0vns"><span class="DDKf1c"><div class="eqA2re UnOTSe Vwoesf" aria-hidden="true"><img class="XNo5Ab" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABwAAAAcCAMAAABF0y+mAAAAS1BMVEVHcEz/UgD/UQD/UAD/UAD/UAD/UQD/UAD/VAD/UQD/RQD/TQD/lHT/uqX/XR7/bDr/f1T/////ybf/qIz/2cz/6N//8uz/OQD/UADG2lzNAAAAGXRSTlMAMoO/5v9b6BXU//////////////////+DKUCQ5AAAARpJREFUeAGEkVWiJTEIBdu4ArGTBHr2v9LpyHOr38JZXlm3/SA69m1dPnO70yv32wf1eNIHno93FekL6y/u1T7oW0bl3o9ZSFje9+1zUsP5wN5Hbn4GtZnbDpKAHIBSql740Oz9ZZp4CQ/AvEspw7pdl61LiSkBCn+ezKfBMxFty96dz1KRFLmU4lNFbnJfDmpUVIoeGdCcXUVt8lioIwWZawkGL8RT0pR0ZguqBphquaR0eQzJNcfiksGnHF7L7sMVOI8shuLgptzHKuxglzdnMEOd0/5b1jEOCkcFYDnkYihNrv18khQkEmKMlHypMBKi+zy8UGoHv2CnWsdtb68vE5oIS38NPf9+9v/hSCb4Ehi+pEk4UePNDgAh4xeJE95/mAAAAABJRU5ErkJggg==" style="height:26px;width:26px" alt=""/></div></span><div class="GTRloc CA5RN"><span class="VuuXrf">Taobao</span><div class="byrV5b"><cite class="qLRx3b tjvcx GvPZzd cHaqb" role="text">https://sg.world.taobao.com<span class="ylgVCe ob9lvb" role="text"> › item</span></cite></div></div></div></div><span jscontroller="IX53Tb" jsaction="rcuQ6b:npT2md" style="display:none"/></a></span><div class="B6fmyf byrV5b Mg1HEd"><div class="HGLrXd iUh30 ojE3Fb"><div class="q0vns"><span class="DDKf1c"><div class="eqA2re UnOTSe" style="height:26px;width:26px"/></span><div class="GTRloc CA5RN"><span class="VuuXrf">Taobao</span><div class="byrV5b"><cite class="qLRx3b tjvcx GvPZzd cHaqb" role="text">https://sg.world.taobao.com<span class="ylgVCe ob9lvb" role="text"> › item</span></cite><div class="eFM0qc BCF2pd iUh30"><span class="LAWljd"> · </span><a class="fl iUh30" href="https://translate.google.com/translate?hl=en&amp;sl=zh-CN&amp;u=https://sg.world.taobao.com/item/661630071666.htm&amp;prev=search&amp;pto=aue" ping="/url?sa=t&amp;source=web&amp;rct=j&amp;opi=89978449&amp;url=https://translate.google.com/translate%3Fhl%3Den%26sl%3Dzh-CN%26u%3Dhttps://sg.world.taobao.com/item/661630071666.htm%26prev%3Dsearch%26pto%3Daue&amp;ved=2ahUKEwjkw4T7x5SFAxX_O0QIHYe2AOoQ7gF6BAgKEAo"><span>Translate this page</span><span jscontroller="IX53Tb" jsaction="rcuQ6b:npT2md" style="display:none"/></a></div></div></div></div></div></div></div></div></div><div class="kb0PBd cvP2Ce LnCrMe" style="grid-area:Vjbam;width:61px;padding-left:20px" data-snf="Vjbam" data-sncf="0,1,2"><div><a href="https://sg.world.taobao.com/item/661630071666.htm" data-ved="2ahUKEwjkw4T7x5SFAxX_O0QIHYe2AOoQ8g16BAgTEAA" ping="/url?sa=t&amp;source=web&amp;rct=j&amp;opi=89978449&amp;url=https://sg.world.taobao.com/item/661630071666.htm&amp;ved=2ahUKEwjkw4T7x5SFAxX_O0QIHYe2AOoQ8g16BAgTEAA"><div aria-hidden="true" style="border-radius:8px;width:61px;height:61px" class="uhHOwf ez24Df"><img alt="" id="dimg_1" src="data:image/gif;base64,R0lGODlhAQABAIAAAP///////yH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" data-deferred="1"/></div></a></div></div><div class="kb0PBd cvP2Ce ieodic" style="grid-area:nke7rc" data-snf="nke7rc" data-sncf="2"><div class="VwiC3b yXK7lf lVm3ye r025kc hJNv6b"><span class="LEwnzc Sqrs4e"><span>1200 × 1200</span> — </span>jk学院风背心格裙套装,好评率100%,45用户购后写下真实评论。品牌:放学后的制服馆,适用年龄:18-25周岁,尺码:XS,S,M,L,XL,2XL,3XL(大码格裙),4XL(大码格裙) ...</div></div></div></div>
2024-03-27 13:36:45.493 | INFO     | __main__:show_result:56 - data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAkGBwgHBgkIBwgKCgkLDRYPDQwMDRsUFRAWIB0iIiAdHx8kKDQsJCYxJx8fLT0tMTU3Ojo6Iys/RD84QzQ5OjcBCgoKDQwNGg8PGjclHyU3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3N//AABEIAD0APQMBIgACEQEDEQH/xAAaAAEBAAMBAQAAAAAAAAAAAAAGBQMEBwIA/8QAOhAAAgEDAgQEAw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qBbrHwnVUMduMkUkgIqwNlXuPU9O3qdEqq3VCjEc0Eh7r4hBB9iBoMRNjarRhszNR2wqzAFqnncHr90AfIddVKe5UdPUKKwwlTnySqGGP8ArRmqFbCDmIj9oHOpLeKz/as4BO7AZOr8aSvI0pDsVVK0b0r0x5IKxCDA+WjYjGevv+d9AbbcpOH7lUUVRnwFlZHjJyVwdm+mPfTl6yOfgW117AuaWvVdhuiuhzn6aP8A6T7ZC09tvEGf7ZCY5mHQyR4APuVZf9uq4TX6T5NLSKFbS0l1oVjnIaAjmhnXrEexB9Pz7c+uEElHWTU0jAtFIVJ9dZ7Nfqq3r4KyjwSejDIXXoQCtnmqJTFJ4jZHhy4x9RpQTrIvpipnjLDlRgjPvgH476L8T08z/aAGVTuQqjI+fXSW2cN08/CM9S9RNzt5iBjGfpqXaIoZqVWkiDOpKlmPNnBx0OsuYnUaHWoDZDCkYJTJ78x1PraiNuRVwFzlsDbTq60dI395To+3Xp+Gjs9rgVmkpWeBh/lbI/5062mC8wv8ESw3qz3iyCUF5Yw8K+ki+ZevY4I+upk11pLxwLUW6WdUuNFWK9NHIcPJ1Vlx+6c+4GhteJqSpkZZ2JmXlfA5eYehx221jMhwa2ACJjlWUbg9idJCtMM0MsLFZEZW9CNYskddNooIrhRRGpQMxQHm75xo5c6FKWo5FYsvbI6ahMiH/9k=
2024-03-27 13:36:45.493 | INFO     | __main__:show_result:57 - 放学后的制服馆/承熙高校/jk格裙毛衣背心马甲针织女半身短裙 ...
2024-03-27 13:36:45.493 | INFO     | __main__:show_result:58 - https://sg.world.taobao.com/item/661630071666.htm
2024-03-27 13:36:45.494 | INFO     | __main__:show_result:59 - --------------------------------------------------

image
I used your demo example, but this happened, and I used the local clash proxy to forward, and the page where the image was found could not be returned correctly. Can you help me check it out?

This is my code

import asyncio

from loguru import logger

from PicImageSearch import Google, Network
from PicImageSearch.model import GoogleResponse

proxies = "http://127.0.0.1:7890"
# proxies = None
url = "https://raw.githubusercontent.com/kitUIN/PicImageSearch/main/demo/images/test03.jpg"
file = "images/test03.jpg"


@logger.catch()
async def test_async() -> None:
    async with Network(proxies=proxies) as client:
        google = Google(client=client)
        # resp = await google.search(url=url)
        resp = await google.search(file=file)
        show_result(resp)
        resp2 = await google.goto_page(resp.get_page_url(2), 2)
        show_result(resp2)


def show_result(resp: GoogleResponse) -> None:
    if not resp:
        return
    # logger.info(resp.origin)  # Original Data
    logger.info(resp.pages)
    logger.info(len(resp.pages))
    logger.info(resp.url)
    logger.info(resp.page_number)
    # try to get first result with thumbnail
    selected = next((i for i in resp.raw if i.thumbnail), resp.raw[0])
    logger.info(selected.origin)
    logger.info(selected.thumbnail)
    logger.info(selected.title)
    logger.info(selected.url)
    logger.info("-" * 50)


if __name__ == "__main__":
    loop = asyncio.get_event_loop()
    loop.run_until_complete(test_async())

Why did you use resp2 = await google.goto_page(resp.get_page_url(2), 2)?
This method was deprecated in version 3.9.0 a year ago.

Listen, I am under no obligation to provide basic instruction for a Python beginner.
You should at least ask something valuable, otherwise, I won't answer any more questions.

Thank you!