chat_session.send_message throw exception while using proxy config: raise ConnectionError(e, request=request) requests.exceptions.ConnectionError: HTTPSConnectionPool(host='generativelanguage.googleapis.com', port=443) #356
Labels
component:python sdk
Issue/PR related to Python SDK
status:triaged
Issue/PR triaged to the corresponding sub-team
type:bug
Something isn't working
Description of the bug:
how can i call the gemini service with proxy service.When I call Gemini's upload file and create cha t session service through the local proxy service, an exception is thrown,i had checked the curl and proxy service ,they both works.here is the exception:
raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='generativelanguage.googleapis.com', port=443): Max retries exceeded with url: /v1beta/models/gemini-1.5-pro-latest:generateContent?%24alt=json%3Benum-encoding%3Dint (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x110fde060>: Failed to establish a new connection: Socket error: [Errno 54] Connection reset by peer'))
###here is the code:,python version 3.12.2,google-generativeai version 0.5.4:
import os
import google.generativeai as genai
from dotenv import load_dotenv
import socket
import socks
socks.set_default_proxy(socks.PROXY_TYPE_HTTP, "127.0.0.1", 10000)
socket.socket = socks.socksocket
load_dotenv()
os.environ["HTTP_PROXY"] = "http://127.0.0.1:9999"
os.environ["HTTP_PROXYS"] = "http://127.0.0.1:9999"
genai.configure(api_key=gemini_key,transport='rest')
generation_config = {
"temperature": 1,
"top_p": 0.95,
"top_k": 64,
"max_output_tokens": 8192,
"response_mime_type": "text/plain",
}
safety_settings = [
{
"category": "HARM_CATEGORY_HARASSMENT",
"threshold": "BLOCK_MEDIUM_AND_ABOVE",
},
{
"category": "HARM_CATEGORY_HATE_SPEECH",
"threshold": "BLOCK_MEDIUM_AND_ABOVE",
},
{
"category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
"threshold": "BLOCK_MEDIUM_AND_ABOVE",
},
{
"category": "HARM_CATEGORY_DANGEROUS_CONTENT",
"threshold": "BLOCK_MEDIUM_AND_ABOVE",
},
]
model = genai.GenerativeModel(
model_name="gemini-1.5-pro-latest",
safety_settings=safety_settings,
generation_config=generation_config,
system_instruction="system instrution")
chat_session = model.start_chat(
history=[
]
)
response = chat_session.send_message("INSERT_INPUT_HERE")
print(response.text)
print(chat_session.history)`
Actual vs expected behavior:
No response
Any other information you'd like to share?
No response
The text was updated successfully, but these errors were encountered: