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

How to search local image (without url) using Google lens by python. #73

Open
xin-ran-w opened this issue Nov 11, 2024 · 0 comments
Open

Comments

@xin-ran-w
Copy link

I have a image store in my local device, and I want to search it on web, here is my code, but it didn't work.

    def encode_pil_to_base64(image):
        buffered = BytesIO()
        image.save(buffered, format="JPEG")
        img_str = base64.b64encode(buffered.getvalue()).decode()
        return img_str
    
    image_url = f"data:image/jpeg;base64,{encode_pil_to_base64(image)}"

    params = {
        "engine": "google_lens",
        "url": image_url,
        "api_key": os.getenv("SERP_API_KEY"),
        "hl": "en",
        "country": "US"
    }
    search = GoogleSearch(params)
    results = search.get_dict()

The error is shown here:

Traceback (most recent call last):
  File "tools.py", line 272, in ...
    results = search.get_dict()
  File "/envs/hddesp/lib/python3.10/site-packages/serpapi/serp_api_client.py", line 103, in get_dict
    return self.get_dictionary()
  File ".../anaconda3/envs/hddesp/lib/python3.10/site-packages/serpapi/serp_api_client.py", line 96, in get_dictionary
    return dict(self.get_json())
  File ".../anaconda3/envs/hddesp/lib/python3.10/site-packages/serpapi/serp_api_client.py", line 83, in get_json
    return json.loads(self.get_results())
  ....
  File ".../anaconda3/envs/hddesp/lib/python3.10/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
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

No branches or pull requests

1 participant