1

My application was working a few weeks ago on Ubuntu Linux. It since has stopped working. I am now just trying to get anything to work from google, which works on my development windows PC. The following code works on my windows PC, it fails on my Linux server.

I have tried to re-install Ubuntu, downgrade python, install Debian on a different external IP address. I even re-generated a new API key with a different google account.

import google.generativeai as genai

#api key
genai.configure(api_key=GOOGLE_API_KEY)


for m in genai.list_models():
    print(m)
    if 'generateContent' in m.supported_generation_methods:
        print(m.name)

model = genai.GenerativeModel('gemini-pro')

response = model.generate_content("Are you working for me today?")
print(response.text)

ERROR:

E0114 21:53:23.743476819   24711 hpack_parser.cc:999]                  Error parsing 'content-type' metadata: invalid value
Traceback (most recent call last):
  File "/home/user/.local/lib/python3.9/site-packages/google/api_core/grpc_helpers.py", line 79, in error_remapped_callable
    return callable_(*args, **kwargs)
  File "/home/user/.local/lib/python3.9/site-packages/grpc/_channel.py", line 1160, in __call__
    return _end_unary_response_blocking(state, call, False, None)
  File "/home/user/.local/lib/python3.9/site-packages/grpc/_channel.py", line 1003, in _end_unary_response_blocking
    raise _InactiveRpcError(state)  # pytype: disable=not-instantiable
grpc._channel._InactiveRpcError: <_InactiveRpcError of RPC that terminated with:
        status = StatusCode.UNKNOWN
        details = "Stream removed"
        debug_error_string = "UNKNOWN:Error received from peer  {grpc_message:"Stream removed", grpc_status:2, created_time:"2024-01-14T21:53:23.743853464+00:00"}"
>

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/user/application2/testgoogle.py", line 8, in <module>
    for m in genai.list_models():
  File "/home/user/.local/lib/python3.9/site-packages/google/generativeai/models.py", line 164, in list_models
    for model in client.list_models(page_size=page_size):
  File "/home/user/.local/lib/python3.9/site-packages/google/ai/generativelanguage_v1beta/services/model_service/client.py", line 677, in list_models
    response = rpc(
  File "/home/user/.local/lib/python3.9/site-packages/google/api_core/gapic_v1/method.py", line 131, in __call__
    return wrapped_func(*args, **kwargs)
  File "/home/user/.local/lib/python3.9/site-packages/google/api_core/retry.py", line 372, in retry_wrapped_func
    return retry_target(
  File "/home/user/.local/lib/python3.9/site-packages/google/api_core/retry.py", line 207, in retry_target
    result = target()
  File "/home/user/.local/lib/python3.9/site-packages/google/api_core/timeout.py", line 120, in func_with_timeout
    return func(*args, **kwargs)
  File "/home/user/.local/lib/python3.9/site-packages/google/api_core/grpc_helpers.py", line 81, in error_remapped_callable
    raise exceptions.from_grpc_error(exc) from exc
  File "/home/user/.local/lib/python3.9/site-packages/google/api_core/exceptions.py", line 616, in from_grpc_error
    details, err_info = _parse_grpc_error_details(rpc_exc)
  File "/home/user/.local/lib/python3.9/site-packages/google/api_core/exceptions.py", line 564, in _parse_grpc_error_details
    status = rpc_status.from_call(rpc_exc)
AttributeError: 'NoneType' object has no attribute 'from_call'

relevant pip

google-ai-generativelanguage 0.4.0
google-api-core              2.15.0
google-auth                  2.26.2
google-generativeai          0.3.2
googleapis-common-protos     1.62.0
grpcio                       1.60.0

Results should look like:

gemini-pro gemini-pro-vision

"Ai response here."

2
  • As near as I can tell, StatusCode.UNKNOWN indicates google is blocking the request. Why it still doesn't work with the hosting provider on a different IP address, I don't know. I was able to successfully get it working with a different provider. If anyone is able to figure out how to address the blocking, I would love to know.
    – DJW
    Commented Jan 15 at 18:31
  • This helped me solve similar error: github.com/googleapis/python-api-core/issues/659 I just installed grpcio-status. Commented Jun 6 at 20:59

0