Getting "_InactiveRpcError" Error for list_model in google-generativeai

Code used:

 

import google.generativeai as google_genai

google_genai.configure(api_key=os.getenv('GOOGLE_API_KEY'))

for m in google_genai.list_models():
    print(m.name)

 

 Error:

 

_InactiveRpcError: <_InactiveRpcError of RPC that terminated with:
	status = StatusCode.UNAVAILABLE
	details = "failed to connect to all addresses; last error: UNKNOWN: ipv6:%5B2404:6800:4009:81e::200a%5D:443: Network is unreachable"
	debug_error_string = "UNKNOWN:Error received from peer  {grpc_message:"failed to connect to all addresses; last error: UNKNOWN: ipv6:%5B2404:6800:4009:81e::200a%5D:443: Network is unreachable", grpc_status:14, created_time:"2024-02-29T21:19:29.044540098+05:30"}"
>

 

The curl command works but the python code doesn't.

 

curl "https://generativelanguage.googleapis.com/v1beta/models?key="$API_KEY

 

 How to solve this issue?

1 REPLY 1

Hi @hrushikeshpawar

Welcome and thank you for reaching out to our community.

The error message you have provided points to an issue with your client application not being able to connect to the gRPC server.

This might be a temporary error that will resolve itself at a later time. A couple of related incidents were reported during the time you are experiencing this error.