google-gemini / generative-ai-python

The official Python library for the Google Gemini API

Home Page:https://pypi.org/project/google-generativeai/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unable to intercept requests to generativelanguages.google

JeevansSP opened this issue · comments

So I'm using a MITM proxy and when I run hit the API endpoint using requests python library, I'm successfully able to see the network trace in my middle man proxy log, but when I use this python package for the same task I'm unable to see the network trace to the generativelanguage.googleapis endpoint.

Hi, this library uses GRPC by default. You can switch it to use rest with:

genai.configure(transport="rest")

Does that fix it for you?

Hi @MarkDaoust, i Iwent through the transport param and you're right if I give it a value of rest it needs to use the rest protocol for the Gemini service, but I'm still unable to see any traces in my MITM network calls when I use that param. I will check if there is anything else wrong and get back

import google.generativeai as genai
genai.configure(transport="rest")

GOOGLE_API_KEY=''

genai.configure(api_key=GOOGLE_API_KEY)

model = genai.GenerativeModel('gemini-1.5-flash')
response = model.generate_content("What is the meaning of life?")
[::1]:63234: POST https://mobile.events.data.microsoft.com/OneCollector/1.0?cors=true&content-type=application/x-json-stream HTTP/2.0
 << HTTP/2.0 200 OK 9b
[13:23:09.340][[::1]:63640] client disconnect
[13:23:09.341][[::1]:63640] server disconnect gateway.icloud.com:443 ([2403:300:1364::2:3]:443)
[::1]:63234: POST https://mobile.events.data.microsoft.com/OneCollector/1.0?cors=true&content-type=application/x-json-stream HTTP/2.0

Those are my mitm logs while I was running the code on vscode
as you can see there is no called to generativeai google apis.
Im successfully able to fetch the response though

Marking this issue as stale since it has been open for 14 days with no activity. This issue will be closed if no further activity occurs.

This issue was closed because it has been inactive for 28 days. Please post a new issue if you need further assistance. Thanks!