Skip to content
This repository has been archived by the owner on Jun 12, 2024. It is now read-only.

The response text is a empty URL, which cannot be seen. {'metadata': ['c_cd648c1c943cb00f', 'r_f093111e78855c35'], 'candidates': {'rcid': 'rc_97ec8a9d7ddbed62', 'text': 'http://googleusercontent.com/card_content/0', 'web_images': [], 'generated_images': []}} #14

Open
LuxerIThink opened this issue Mar 6, 2024 · 8 comments
Assignees
Labels
good first issue Good for newcomers

Comments

@LuxerIThink
Copy link

Describe the bug
The response text is returned in a URL format that cannot be seen.

Version
OS: Windows 11
Python: 3.12.2
Gemini API: 1.0.4
Using proxy: No
Region: Poland

Code

from gemini import Gemini

cookies = {
    "__Secure-1PSID" : "fullfilled",
    "__Secure-1PSIDTS" : "fullfilled",
    "__Secure-1PSIDCC" : "fullfilled", # I use this because in BardCookies it works
    "NID" : "fullfilled",
  }

GeminiClient = Gemini(cookies=cookies)

prompt = "Hello, Gemini. What's the weather like in Seoul today?"
response = GeminiClient.generate_content(prompt)
print(response)

Error

{'metadata': ['c_cd648c1c943cb00f', 'r_f093111e78855c35'], 'candidates': {'rcid': 'rc_97ec8a9d7ddbed62', 'text': 'http://googleusercontent.com/card_content/0', 'web_images': [], 'generated_images': []}}
@dsdanielpark
Copy link
Owner

Hello, LuxerIThink

This has already been developed and will be updated today.

It will be provided as asynchronous code that can save to a bytetype image or path. Thank you for your valuable feedback!

@opnoice
Copy link

opnoice commented Mar 9, 2024

Getting same error

@dsdanielpark
Copy link
Owner

Getting same error

Please, try to this code.

from gemini import Gemini, GeminiImage

response = GeminiClient.generate_content("Create illustrations of Seoul, South Korea.")
generated_images = response.generated_images # Check generated images [Dict]

GeminiImage.save_sync(generated_images, save_path="cached")

# You can use byte type image dict for printing images as follow:
bytes_images_dict = GeminiImage.fetch_images_dict_sync(generated_images, cookies) # Get bytes images dict
from IPython.display import display, Image
import io

for image_name, image_bytes in bytes_images_dict.items():
    print(image_name)
    image = Image(data=image_bytes)
    display(image)

# GeminiImage.save_images_sync(bytes_images_dict, path="cached") # Save to path

@LuxerIThink
Copy link
Author

Getting same error

Please, try to this code.

from gemini import Gemini, GeminiImage

response = GeminiClient.generate_content("Create illustrations of Seoul, South Korea.")
generated_images = response.generated_images # Check generated images [Dict]

GeminiImage.save_sync(generated_images, save_path="cached")

# You can use byte type image dict for printing images as follow:
bytes_images_dict = GeminiImage.fetch_images_dict_sync(generated_images, cookies) # Get bytes images dict
from IPython.display import display, Image
import io

for image_name, image_bytes in bytes_images_dict.items():
    print(image_name)
    image = Image(data=image_bytes)
    display(image)

# GeminiImage.save_images_sync(bytes_images_dict, path="cached") # Save to path

Code you give us in here can't work (because cookies are not defined), but this is problem with texts not with images (I don't tested them).

@dsdanielpark dsdanielpark changed the title The response text is a URL, which cannot be seen. The response text is a empty URL, which cannot be seen. Mar 17, 2024
@dsdanielpark
Copy link
Owner

dsdanielpark commented Mar 17, 2024

LuxerIThink, opnoice

Possible Solutions

Most of all, try rerunning the generate_content method without redeclaring the Gemini object.

  1. Initial Empty Response: Check if the first response is empty due to initial data fetching by the application. Retry after a short wait.

    • The initial response to your request might be empty, possibly due to the Gemini application fetching initial data. This seems to involve some operation by internal middleware or routers, indicated by fetching values from URLs starting with 'execute', leading to the first response being empty.
  2. Premature Response: Wait for a minute after the first attempt if the server settings might not be complete. Avoid redeclaring the Gemini object.

    • This might occur if Gemini's web UI hasn't completed server settings, fetching a premature response. Wait about a minute after the first attempt before running the generate_content method again. Ensure not to redeclare the Gemini object, as repeated object declarations or exporting cookies can lead to 'undefined' cookie values and errors. It's suspected that internal interfaces might reset cookies upon detection, possibly through a RotateCookie process.
  3. Logout and Restart: Log out from all synchronized Chrome accounts, cancel synchronization, and restart the browser.

    • Log out of all synchronized accounts in Chrome, cancel synchronization, and restart your browser. Synced accounts might prevent proper operation.
  4. Cookie Sync Issues: If the same cookies work on one PC but not another, try a fresh browser environment or delete all cookies before accessing Gemini again.

    • Cookie values might sync with the browser's metadata. The same cookies worked on one PC but not another, despite identical inputs. One PC could use the same cookie for over a month. Try executing your code on a completely fresh Chrome environment or manually delete all cookies before accessing Gemini. If issues persist, consider reinstalling the browser.
  5. New Account or Region: Create a new Google account or set a new default country in the account settings.

  6. Valid Cookies in Different Environments: Try using a different Google account in a new browser if valid cookies do not work.

  7. Few Valid Cookies: Input a small number of valid cookie values as suggested on the authentication section, may require country-specific experimentation.

  8. Other User Solutions: Look at solutions provided by other users on the issue page.

If you've found a suitable solution to this issue, please share your experience on this issue page. Thank you.

@dsdanielpark dsdanielpark changed the title The response text is a empty URL, which cannot be seen. The response text is a empty URL, which cannot be seen. {'metadata': ['c_cd648c1c943cb00f', 'r_f093111e78855c35'], 'candidates': {'rcid': 'rc_97ec8a9d7ddbed62', 'text': 'http://googleusercontent.com/card_content/0', 'web_images': [], 'generated_images': []}} Mar 18, 2024
@dsdanielpark dsdanielpark added the good first issue Good for newcomers label Mar 18, 2024
@dsdanielpark
Copy link
Owner

Hey, guys!

Make sure you're using version 2.4.2 or later and manually pass the complete cookie (avoid using auto_cookie).

Please test this script with the complete set of cookies collected manually:
https://github.com/dsdanielpark/Gemini-API/blob/main/scripts/sample.ipynb

@dsdanielpark
Copy link
Owner

Using VPN or public IP, facing temporary blocks like 429 errors (due to repeated requests or authentication attempts) can disrupt the SSL/TLS handshake, resulting in an empty response. This issue isn't limited to specific accounts and might require IP-based circumvention.

@fredmo
Copy link

fredmo commented May 8, 2024

Still with the return message :

{'metadata': ['c_c4d1c4aed0cb5eXX', 'r_3214ea893c673dXX'], 'prompt_class': None, 'prompt_candidates': [], 'candidates': [{'rcid': 'rc_5fbed4cbaf9e71XX', 'text': 'http://googleusercontent.com/card_content/0', 'code': {}, 'web_images': [], 'generated_images': []}]}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

4 participants